Answer the question
In order to leave comments, you need to log in
HTACCESS 301 site alias redirect?
Good afternoon,
there are aliases of the main site, how to redirect them to the main one?
there used to be an entry in htaccess like this:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^site.ru$ [NC]
RewriteRule ^(.*)$ http://www.site.ru/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^(.*)?site-alias1.ru$ [NC]
RewriteRule ^(.*)$ http://www.site.ru/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^(.*)?site-alias2.ru$ [NC]
RewriteRule ^(.*)$ http://www.site.ru/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^(.*)?site-alias3.ru$ [NC]
RewriteRule ^(.*)$ http://www.site.ru/$1 [R=301,L]
RewriteCond %{ENV:HTTPS} !on
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
Answer the question
In order to leave comments, you need to log in
RewriteEngine On
# если пришел по http редиректим на https
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# если без www редиректим на https://www.
RewriteCond %{HTTP_HOST} ^site.ru$ [NC]
RewriteRule ^(.*)$ https://www.site.ru/$1 [R=301,L]
# если www.alias редиректим на https://www.
RewriteCond %{HTTP_HOST} ^(.*)?site-alias1.ru$ [NC]
RewriteRule ^(.*)$ https://www.site.ru/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^(.*)?site-alias2.ru$ [NC]
RewriteRule ^(.*)$ https://www.site.ru/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^(.*)?site-alias3.ru$ [NC]
RewriteRule ^(.*)$ https://www.site.ru/$1 [R=301,L]
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question