Forum Moderators: phranque
I'm working on touching up a domain redirect script I have, hoping somebody might be able to give some improvement tips:
RewriteCond %{HTTP_HOST} ^domain\.com$ [NC]
RewriteRule (.*) [www\.domain\.com...] [R=301,L]
RewriteCond %{HTTP_HOST}!^www\.domain\.com$ [NC]
RewriteCond $1!^typo-domain\.php$
RewriteRule (.*) /typo-domain.php?url=$1 [L]
Two parts to the script. The first part is to redirect from non-www version of a domain to the www version of the domain.
The second part of the script looks to see if it is the www version (which it now should be if was the non-www version of the domain name), else, send the visitor to a special script can store that domain to a database and to 301 redirect them from there to the correct page. (I'm using that to be able to count typo variants of my domain.)
Is this the best way to do this? Seems kind of bulky.
Originally I had this as it was either the correct domain with www, or it was redirected to my script. Seemed kind of wasteful for people who just forgot the www section.
RewriteCond %{HTTP_HOST} ^domain\.com [NC]
-or-
RewriteCond %{HTTP_HOST} ^domain\.com(:80)?$ [NC]
-or-
RewriteCond %{HTTP_HOST} ^domain\.com(:[0-9]{1,5})?$ [NC]
Jim