D
D
Dudoroff2021-11-03 21:01:36
htaccess
Dudoroff, 2021-11-03 21:01:36

How to make one redirect to all htaccess rules?

there is a set of rules

# Переадресация с добавлением / в конце
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^([^.]+)(?<!/)$ /$1/ [R=301,L]

    # редирект на https://
    RewriteCond %{HTTPS} =off
    RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,QSA]

    # Переадресация с домена с WWW на домен без WWW
    RewriteCond %{HTTP_HOST} ^www\.(.*) [NC]
    RewriteRule ^(.*)$ https://%1/$1 [R=301,L]

If we need, for example, to remove www, add https, and even / at the end we get 3 redirects. How to make sure that if necessary, the rules are applied one after another and in the end there is only 1 correct redirect?

Tried like this:
# редирект на https://
    RewriteCond %{HTTPS} =off
    RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [E=RCODE:301,QSA]

    # Переадресация с домена с WWW на домен без WWW
    RewriteCond %{HTTP_HOST} ^www\.(.*) [NC]
    RewriteRule ^(.*)$ https://%1/$1 [E=RCODE:301]

    # Переадресация с добавлением / в конце
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^([^.]+)(?<!/)$ /$1/ [E=RCODE:301]

    RewriteCond %{ENV:RCODE} !^$
    RewriteRule (.*) /$1 [R=${ENV:RCODE},L]


As a result, the domain is copied many times in the address bar and the redirect does not understand where

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question