Answer the question
In order to leave comments, you need to log in
Redirect from www.example.com to example.com (apache2, ubuntu 10.04)?
Good day to all!
I ran into such a problem - you need to organize a redirect on the site from www.example.com to example.com
Google gave two main pieces of advice: this is mod_rewrite with redirect conditions like
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
<VirtualHost *>
ServerName www.example.com
Redirect 301 / http://example.com/
</VirtualHost>
Answer the question
In order to leave comments, you need to log in
One $ character difference in the first line
RewriteCond %{HTTP_HOST} ^www\.(.*) [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
in .htaccess
www
www
if suddenly it doesn't work add over the selected option
RewriteCond %{HTTP_HOST} ^www.domain\.com$ [NC]
RewriteRule ^(.*)$ domain.com/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^domain\.com$ [NC]
RewriteRule ^(.*)$ www.domain.com/$1 [R=301,L]
Options +FollowSymLinks
RewriteEngine On
If nginx is in front of Apache, then it is better for them to organize a redirect
RewriteEngine on
RewriteCond %{HTTP_HOST} !^se\.solovyev\.org$
RewriteRule ^ se.solovyev.org% {REQUEST_URI} [R=301,L]
Github code
<IfModule mod_rewrite.c>
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ %1% {REQUEST_URI} [R=301,L]
here is the smartest option from the boilerplate. Almost the same as in comment n.1
The option I always use:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ http%{ENV:protossl}://%1%{REQUEST_URI} [L,R=301]
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question