Forum Moderators: phranque

Message Too Old, No Replies

301 redirect

         

Mark1978

9:46 am on Aug 17, 2010 (gmt 0)

10+ Year Member



]Hi I have few 301 redirects to write from an old domain to a new domain. Here is an example of the redirect that I need to write.

www.olddomain.co.uk/test

www.newdomain.test.co.uk/new/test/

I have written a rule below. I can't test it as yet. but will this work

RewriteCond %{HTTP_HOST} ^www\.olddomain\.co\.uk/test/$ [NC]
RewriteRule ^(.*)$ www.newdomain.test.co.uk/new/test/ [L,R=301]

Thanks

wildbest

12:01 pm on Aug 17, 2010 (gmt 0)

10+ Year Member



but will this work

Probably not

Try this:

RewriteCond %{HTTP_HOST} ^www\.olddomain\.co\.uk$ [NC]
RewriteCond %{REQUEST_URI} ^test/ [NC]
RewriteRule ^test/(.*)$ http://www.example.test.co.uk/new/test/$1 [R=301,L]

Alternatively you can try this:

RewriteCond %{HTTP_HOST}>%{REQUEST_URI} ^www\.olddomain\.co\.uk>/?test/(.*)$ [NC]
RewriteRule .* http://www.example.test.co.uk/new/test/%1 [R=301,L]

[edited by: wildbest at 12:14 pm (utc) on Aug 17, 2010]

jdMorgan

12:10 pm on Aug 17, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Or just

RewriteCond %{HTTP_HOST} ^(www\.)?olddomain\.co\.uk [NC]
RewriteRule ^test/(.*)$ http://www.example.test.co.uk/new/test/$1 [R=301,L]

to catch more 'variations' of the olldomomain hostname -- www- and non-www, FQDN, and appended ports, for example.

Note that the RewriteCond testing %{REQUEST_URI} is not needed -- the URL-path is already being tested by the rule itself.

This code in it's current form assumes that all domains are hosted in the same 'file space' so that this .htaccess file will be executed when a browser makes a request for "www.olddomain.com". If these old domains are hosted separately, then the remaining RewriteCond won't be needed either -- as long as the code is located in a .htaccess file that will be processed when that domain is requested.

Jim