M
M
MrOnatsky2018-07-12 05:25:28
Apache HTTP Server
MrOnatsky, 2018-07-12 05:25:28

Correct redirect to https | config or htaccess?

Good afternoon. How to redirect to https correctly? Through site configs or through htaccess? And how right? There are a lot of examples in Google, and everyone is different, and FIG understand how it is correct and / or better. Now redirect through the config:

ServerName site.com
ServerAlias www.site.com
#Redirect / https://site.com
Redirect / https://site.com/

Previously, there was no slash at the end, but when going to http site.com/lalala.php it was redirected to https site.comlalala.php I added a
slash, and it seemed to work fine. But damn, even this method of "intuitive poke" alarms me. Although in all the examples that I saw there was a redirect to the site address without a slash, so I did, and then bam, such jokes.

Or is it better to remove the redirect in the config, direct it to the root of the site, and do the redirect in htaccess through rewrite? If yes, how is it right? Thanks in advance!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Viktor Taran, 2018-07-12
@shambler81

We remove

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

add
RewriteCond %{HTTP_HOST} !^www\.(.*) [NC] 
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$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