Forum Moderators: phranque
I'm trying yo ensure that if anyone puts just the http or just the www, that it will still go to [sitename.com...] but when I try the code below, it doens't work, am I missing a bit somewhere pease?
Any help much appreciated.
Sev.
RewriteEngine on
RewriteCond %{HTTP_HOST} ^sitename.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.sitename.com$
RewriteRule ^(.*)$ [sitename.com...] [R=301,L]
Don't end-anchor your HOST names. Otherwise, an appended port number will break your code.
If I missed your point, please tell us what you mean by "it doesn't work."
Jim
Just to clarify what I'm trying to attempt, assuming it is possible ;-)
I'm trying to do it, so that if someone inputs:
[sitename.com...]
or
www.sitename.com
or
sitename.com
they are always redirected via a 301 redirect to:
[sitename.com...]
I'm on an Apache server and have access to the .htaccess file.
I've been struggling with this for a few weeks and would really appreciate a hand on it.
Sev.
Understand that the user has no control over "entering" the "http://". If the user does not enter that, then the browser will add it automatically. The request *must* have a protocol specified, such as http, https, or ftp, before any connection to your server is possible. Therefore, the only case you have to worry about is a missing "www.". Since you tried to redirect www.sitename.com to www.sitename.com, your server looped doing redirects until the maximum number of allowed redirects was reached, either by your server or by your browser.
This should be all you need:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^sitename\.com
RewriteRule (.*) http://www.sitename.com/$1 [R=301,L]
See our charter [webmasterworld.com] for links to useful references on mod_rewrite and regular expressions.
Jim
I have another post to make in a bit, in a new thread on this forum, hopefully I'll get some good help on that one as well - I have been through the threads and charter on it, but this next one hasn't been covered anywhere as far as I can tell.
Sev.