still the best way to handle the www, as opposed to a 301 redirect?
Do you think I should redirect to www or redirect to no www. I think I’m going to redirect to No www, it’s a cleaner look, “www” is not so new anymore.
If so, then I would have to use:
RewriteCond %{HTTP_HOST} ^www.xyz.com
RewriteRule ^(.*)$ http://xyz.com/$1 [r=301,L]
First, escape the dot character in your {HTTP_HOST} regex.
Second, that would have no effect on the mod_rewrite code so it’s likely that:
mod_rewrite is not enabled. If this were the case, though, you’d have received a 505 error message (because the mod_rewrite code would not have been understood.
Your host has not enabled the use of .htaccess on your server.
You are being hosted on an M$ server (i.e., not Apache).
To be sure, read the part in my tutorial about setting up a server and TESTING that mod_rewrite is enabled and functioning. Run the simple test then come back with the results.
Same thing except slower because my .? version sending the %{REQUEST_URI} is the SAME as capturing the {REQUEST_URI} to $1 and adding that to the domain redirection. Six of one, half dozen of the other as it’s only slightly more than a matter of style.
Whoops! There should be NO backslashes in the redirection, ONLY IN {regular expressions}. In that code, the RewriteCond’s ^www\.xyz\.com$ is regex and .? in the RewriteRule is regex.
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\\.xyz\\.com$ [NC]
# match {HTTP_HOST} start-of-string www dot xyz dot com end-of-string No Case
RewriteRule .? http://xyz.com%{REQUEST_URI} [R=301,L]
# match anything and permanently redirect to http://xyz.com with the same request ({REQUEST_URI} string)
DK,
That works fine, although it didn’t look like it worked at first because IE holds on to its cached copy much more that FF. You have to use Ctrl F5 regularly with IE when testing pages.