Forum Moderators: phranque

Message Too Old, No Replies

Combining www removal and domain redirect

.htaccess bad practice to do it this way?

         

limbo

9:04 pm on May 16, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi

Spot the code hack... I'm using the .htaccess commands below to forward users from the one domain to another regardless of whether they use the www:

#-----------------------------------------

Options +FollowSymLinks
RewriteEngine on

RewriteCond %{HTTP_HOST} ^www\.onedomain\.co.uk [NC]
RewriteCond %{QUERY_STRING} ^(.*)$
RewriteRule ^(.*)$ http:// www.anotherdomain.com/$1?%1 [R=301,L]

RewriteCond %{HTTP_HOST} ^onedomain.co.uk
RewriteRule (.*) http:// www.onedomain.co.uk/$1 [R=301,L]

#----------------------------------------- (delinkled)

Am I OK combining them in this way or is there a slimmer method? this way seems a bit loopy

Cheers, Limbo.

jdMorgan

10:41 pm on May 16, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



1) What is the query string manipulation intended to do?
2) Do you want to redirect "anotherdomain.com" to www.anotherdomain.com? - Your current code doesn't do that.

Jim

limbo

8:03 am on May 17, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



jd

The first line forwards people from www.onedoamin.co.uk to www.anotherdomain.com

The second command catches people who type the domain without the www and then the first command kicks in again and send them to the correct address - the code works, I've tried it... but is there a cleaner way?

jdMorgan

1:47 pm on May 17, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Please answer those two questions directly... I cannot answer your questions correctly without knowing the answer to those. Once again:

1) Why are you testing the query string in the first rule?
2) Do you want to redirect "anotherdomain.com" to "www.anotherdomain.com", or to leave it alone?

Jim