Welcome to WebmasterWorld Guest from 54.226.189.112

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

Force Remove of www causes error

     

chasehx

8:50 pm on Dec 21, 2009 (gmt 0)

5+ Year Member



I am removing the wwww from my domain because it is old and I do not need it. I have tried 40983040909 different examples and it does not work. This one should work, but throws the server into an infinite loop. this is right from a tutorial I have used before

RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.example.com$ [NC]
RewriteRule ^(.*)$ http://example.com/$1 [R=301,L]

I have the server set up as a virtual host with ServerAlias. Is that making it not work?

jdMorgan

11:15 pm on Dec 21, 2009 (gmt 0)

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member



What kind of 'loop' -- an external redirection loop (multiple browser HTTP redirects and requests), or an internal rewriting loop?

Is there anything in your server error log?

Is UseCanonicalName set to "on" with the "www" hostname declared as the (incorrect) canonical ServerName?

Are there any other RewriteRules or mod_alias directives which may be interfering?

BTW, don't end-anchor the pattern used to check the hostname. Or if you do feel you need to end-anchor it, then follow the ".com" with \.?(:[0-9]+)?$ so that FQDNs and hostnames with appended port numbers won't defeat the rule. Also, escape all literal periods in regex patterns by preceding them with "\":

 RewriteCond %{HTTP_HOST} ^www\.example\.com\.?(:[0-9]+)?$ [NC] 

An alternative, if you don't plan to use subdomains in additional to "www", would be to redirect anything that is *not* exactly the canonical hostname:

 RewriteCond %{HTTP_HOST} !^example\.com$ 

(Note negated pattern, no FQDN or port allowed, no uppercase allowed -- all would get redirected to all-lowercase "example.com")

Jim

 

Featured Threads

Hot Threads This Week

Hot Threads This Month