Dez
February 3, 2017, 11:21am
1
To ensure that your site always appears with www. at the very beginning, I’ve been working through some coding for it, but the below comes back as an error, can you see where it’s wrong please?
RewriteEngine on
RewriteCond %{HTTP_HOST} ^http://www.site.com$ [OR]
RewriteCond %{HTTP_HOST} ^http://site.com$ [OR]
RewriteCond %{HTTP_HOST} ^site.com$
RewriteRule ^(.*)$ www.site.com/$1 [R=301,L]
Gandalf
February 3, 2017, 11:26am
2
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.example\.com$ [NC]
RewriteRule .? http://www.example.com%{REQUEST_URI} [R=301,L]
Dez
February 3, 2017, 11:28am
3
Thank you for the quick response, would that still redirect even if it started with http ?
Gandalf
February 3, 2017, 11:30am
4
Yes, the HTTP_HOST doesn’t include the protocol.
You might find this site useful.
Dez
February 3, 2017, 11:43am
5
It doesn’t work if it’s http://site.com
Gandalf
February 3, 2017, 12:24pm
6
It should do. I’m sure you’ve checked for typos but are there any other directives in your .htaccess that may cause a problem?
Dez
February 3, 2017, 12:27pm
7
Have checked and no typos and no conflicting directives. Could you try it on yours please.
Gandalf
February 3, 2017, 12:42pm
8
This is what I use on most of my sites. All it’s missing is the [NC] no case flag.
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.domain\.eu$
RewriteRule .? http://www.domain.eu%{REQUEST_URI} [R=301,L]
Dez
February 3, 2017, 12:43pm
9
Thank you. Is it okay to use the NC though?
Dez
February 9, 2017, 9:53am
11
Thanks Gandalf, this is still the best forum around.
3 Likes
system
Closed
May 11, 2017, 4:53pm
12
This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.