Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Rewriting from a subfolder to the root

  • 23-04-2012 04:09PM
    #1
    Registered Users, Registered Users 2 Posts: 4,475 ✭✭✭


    Man, every time I mess around with the RewriteEngine, I just get more and more confused, no matter how much I read up on it.

    This weekend, I'll be moving my site to a new host, and am going to take the opportunity to make some changes. For the last year or so, for legacy reasons, I've had my actual site in www.domain.com/ver2/, while www.domain.com shows the original. No longer! I'm going to transfer the contents of the /ver2 subfolder on my old host to the root on my new host.

    However, there will still be links out there pointing to /ver2, so I'd like that when they come in, there's a permanent redirect to the root, but everything else is left intact. Filenames, parameters, etc etc, all as is.

    I tried
    RewriteEngine On
    RewriteBase /~domain/
    RewriteRule ^ver2/(.*)$ /$1 [R=301,NC,L]
    
    in a .htaccess in the root of my new host (and I also created a ver2 folder and popped it in there) but if I try
    http://91.216.241.2/~domain/ver2/test.php?name=michael
    
    where test.php is a file only in the root, I get 404.

    I was hoping this would do it, and then when I go live this weekend, I'd simply remove the '~domain/' part of the RewriteBase and I'm done, but instead I'm stuck. I know it's something dumb I'm doing, but no amount of Googling is helping me.


Comments

  • Closed Accounts Posts: 7,144 ✭✭✭DonkeyStyle \o/


    I'm not a whizz with .htaccess either (I pretty much hit it with a hammer until it works and hope the universe doesn't break it), but I was curious enough to have a play around with it.
    I got a 404 until I removed the forward-slash (marked in red), after which it worked as expected. The .htaccess was only in /~domain/
    RewriteEngine On
    RewriteBase /~domain/
    RewriteRule ^ver2/(.*)$ [COLOR="Red"][B]/[/B][/COLOR]$1 [R=301,NC,L]
    


  • Registered Users, Registered Users 2 Posts: 4,475 ✭✭✭corblimey


    I'm not a whizz with .htaccess either (I pretty much hit it with a hammer until it works and hope the universe doesn't break it), but I was curious enough to have a play around with it.
    I got a 404 until I removed the forward-slash (marked in red), after which it worked as expected. The .htaccess was only in /~domain/

    Hi DonkeyStyle. It was a bit difficult for me to see the red in the code section until I actually started this reply. I finally had it working with
    RewriteEngine On
    RewriteRule ^ver2/(.*)$ http://ipaddress/~domain/$1 [R=301,NC,L]
    
    but I prefer your approach. Thanks!


Advertisement