Answer the question
In order to leave comments, you need to log in
.htaccess rules. Why is a chain of redirects formed and the main page at www. gives response code 302 instead of 301?
I audit the site using ahrefs.com and see:
As far as I understand, from htр://www . The main page first has a temporary 302 redirect to https://www . main, and from it to https:// main (without www), although immediately with httр://www . https:// (without www) should go.
.htaccess content:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
# BEGIN Ahrefs
Redirect 301 http://mysite.ru/ https://mysite.ru/
Redirect 301 http://www.mysite.ru/ https://mysite.ru/
Redirect 301 https://www.mysite.ru/ https://mysite.ru/
# END Ahrefs
#RewriteEngine On # Если этой строки нет выше
RewriteCond %{HTTP:X-Forwarded-Protocol} !=https
RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]
Answer the question
In order to leave comments, you need to log in
I'm certainly an expert, but why are you putting these redirects after the WordPress block? After all, there must be before.
Separate redirects for the main page are superfluous, they should be processed according to general rules.
I did this myself:
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^(.*)$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R]
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question