Y
Y
Yuriy2017-01-20 14:00:26
Apache HTTP Server
Yuriy, 2017-01-20 14:00:26

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]


Received an HTTPS certificate

, made a redirect from http to https,

changed HTACCESS like this:

RewriteCond %{ENV:HTTPS} !on
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]


how to redirect correctly now Aliases to https://www.site.ru

appear like this garbage when entering from an alias...316c744b33354f2c8391d4e0429c4c84.png

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vitaliy Orlov, 2017-01-20
@orlov0562

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]

V
Viktor Taran, 2017-04-27
@shambler81

make redirects here CNAME

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question