M
M
mousesport2017-04-27 12:06:41
Apache HTTP Server
mousesport, 2017-04-27 12:06:41

Redirecting https to non-WWW and http to www?

There is a rule in htaccess

RewriteCond %{HTTP_HOST} ^site.ru
RewriteRule (.*) www.site.ru/$1 [R=301,L]

which makes 301 redirects both https and http to www
is it possible to make https redirect all requests to https://site.ru/$1
and http redirect to www.site.ru/$1

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
mousesport, 2017-04-27
@mousesport

thanks Victor Taran @shambler81
what's the problem then?

RewriteCond %{SERVER_PORT} ^443$
RewriteCond %{HTTP_HOST} ^www\.(.*) [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
RewriteCond %{SERVER_PORT } !^443$
RewriteCond %{HTTP_HOST} !^www\.(.*) [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

V
Viktor Taran, 2017-04-27
@shambler81

RewriteCond %{HTTP} On
RewriteCond %{HTTP_HOST} ^site.ru
RewriteRule (.*) www.site.ru/$1 [R=301,L]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question