Answer the question
In order to leave comments, you need to log in
How to make single 301 redirect with htaccess?
To redirect from www and http to https, I use the following code in .htaccess:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^www.site\.ru$ [NC]
RewriteRule ^(.*)$ https://site.ru/$1 [R=301,L]
</IfModule>
RewriteCond %{REQUEST_URI} !"^/$"
RewriteRule (.+) https://%{HTTP_HOST}/ [R=301,L]
https://www.site.ru/fghdgsdf
leads to https://site.ru/fghdgsdf,
and only then to https://site.ru/
. Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question