Forum Moderators: phranque

Message Too Old, No Replies

Weekly 301 redirect question

folder to new domain

         

Powdork

1:37 am on May 28, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I must confess i didn't go through all the 301 threads here before posting, but I did look at many without finding my answer. I want to break a directory offf my current domain to a new one witout losing the incoming links which I have gotten to most of the main pages within the directory. So, in a nutshell I want everything below www.olddomain.com/foldername/ to redirect to the corresponding pages of foldername.com (yes, the new domain name is the same name as the old folder name, and all the pages will be named the same). With my complete lack of knowledge (but growing) in the area, this is what I have come up with. This is just a guess and I'm hoping you guys will tell me how wrong I am, and where.

RewriteEngine on
RewriteCond %{HTTP_HOST}!^www\.olddomain\.com\/foldername\
RewriteRule (.*) [foldername.com...] [R=301,L]

TIA

Birdman

2:03 am on May 28, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hello Powdork,

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]

Powdork

3:27 am on May 28, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thx Birdman,
So if I put it within foldername/ I would just have

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?

Birdman

11:38 am on May 28, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



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