Forum Moderators: phranque
RewriteEngine on
RewriteCond %{HTTP_HOST}!^www\.olddomain\.com\/foldername\
RewriteRule (.*) [foldername.com...] [R=301,L]
TIA
You shouldn't need the conditional(rewritecond) statement. Personally, I think putting a separate .htaccess folder in the 'foldername' folder is the best route. Then, the server only has to process the rules when the request comes from that folder, rather than ALL requests. Plus it's much safer to test in sub-directories so you don't kill the whole site when you mess up.
The examples below are for normal root folder .htaccess usage. If you want to test in a sub-directory, simply remove 'foldername/' from the left part of the rewrite rule.
RewriteEngine on
RewriteRule ^foldername/(.*) h-tp://www.foldername.com/$1 [R=301,L]
That should redirect:
oldname.com/foldername/foo...to...foldername.com/foo
If you wanted this:
oldname.com/foldername/foo...to...foldername.com/foldername/foo
Then just add the foldername:
RewriteRule ^foldername/(.*) h-tp://www.foldername.com/foldername$1 [R=301,L]
RewriteEngine on
RewriteRule ^(.*) h-tp://www.foldername.com/$1 [R=301,L]
with the h-tp relinkified.
1. Do I need the Rewrite engine on given that it exists in the root folder? (or more precisely, will it mess things up given that it's already in the root?)
2. Can I get rid of everything else in the folder (on the old domain), or do I need to keep all the subdirectories intact?
3. Can I keep it there forever, or is there a time frame?
4. Is it really that easy?
Oh yeah, this is for Apache, *nix based servers, right?
Do I need the Rewrite engine on given that it exists in the root folder? (or more precisely, will it mess things up given that it's already in the root?)
I would imagine you need it and I really doubt it will mess things up. One way to find out is to try it without the 'rewriteEngine on' line.
Can I get rid of everything else in the folder (on the old domain), or do I need to keep all the subdirectories intact?
Yes, you can empty the folder, except the .htaccess file of course ;) Or, you can leave the files there if you wish.
Can I keep it there forever, or is there a time frame?
No time frame. I would hope that after some time the requests for the old files would stop, but unfortunately I still get requests for files two years after they were renamed/relocated. Since you plan to keep the original site intact, I would just leave it there indefinately.
Is it really that easy?
Heck yes! Isn't it sweet? I wouldn't want to host on a M$ server if it was free :)
Oh yeah, this is for Apache, *nix based servers, right?
Correct, although it should work on Apache/Win too.
Here's what you can do to get in there and 'get your hands dirty'. Create a test folder and then put an .htaccess file in there and play around with it. This way, any errors should stay local to that folder and not mess up your live site.
Have fun and good luck!
Birdman