A
A
artem993572020-04-21 22:41:28
URL Handling
artem99357, 2020-04-21 22:41:28

What should be a 301 redirect?

Greetings.
It is necessary to configure the redirect correctly so that the site opens https://site.ru/folder
1. Redirect from www to without www ;
2. Redirect from http:// to httpS:// ;
3. Redirect from /index.html to without /index.html ;
4. Removing "/" at the end of folders.
In .htaccess, this is the code:

RewriteEngine On

RewriteCond %{HTTP:X-Forwarded-Protocol} !=https
RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]

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

RewriteRule ^index\.html$ / [R=301,L]
RewriteRule ^(.*)/index\.html$ /$1/ [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^(.+)/$
RewriteRule ^(.+)/$ %1 [R=301,L]


With this option, it turns out:
- When accessing a site like http://site.ru/folder
302 Redirect https://site.ru/folder
301 Moved forever http://site.ru/folder/
‎ 302 Redirect https:/ /site.ru/folder/

‎ - When accessing a site like httpS://site.ru/folder
301 Moved forever http://site.ru/folder/
‎ 302 Redirect https://site.ru/folder/
301 Moved forever http://sayt.ru/folder
302 Redirect https://sayt.ru/folder
‎ 301 Moved forever http://sayt.ru/folder/
‎ 302 Redirect https://sayt.ru/folder/
‎ 301 Moved forever http://site.ru/folder
302 Redirect https://site.ru/folder
‎ 301 Moved forever http://site.ru/folder/
‎ 302 Redirect https://site.ru/folder/

‎ How to avoid heaps of redirects, what should htaccess be?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Viktor Taran, 2020-04-22
@shambler81

I wrote everything here
https://klondike-studio.ru/standards/standartnyy-h...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question