G
G
gh0st_d0g2020-03-11 13:19:53
htaccess
gh0st_d0g, 2020-03-11 13:19:53

How to fix htaccess to merge 2 redirects into 1?

RewriteCond %{THE_REQUEST} /(.*)index.php.*$
RewriteRule .* /%1 [R=301,L]

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

RewriteCond %{QUERY_STRING} ^oid=(.*)
RewriteRule ^(.*)$ /$1? [R=301,L]

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

There are 4 redirects. It is necessary that when a request is made to an address of the form localhost/contacts/index.php , a redirect to the address https://localhost/contacts/ occurs immediately in 1 redirect. Now there are 2 redirects. And from www.localhost/contacts/index.php directly to https://localhost/contacts/ . It is necessary somehow to bring all these 3 rules to one.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
dodo512, 2020-03-11
@dodo512

RewriteCond %{REQUEST_URI} /[^/.]+$
RewriteRule ^(.*)$ https://localhost/$1/ [R=301,L]

RewriteCond %{THE_REQUEST} /index\.php [OR]
RewriteCond %{HTTPS}       !on         [OR]
RewriteCond %{HTTP_HOST}   ^www\.      [NC]
RewriteRule ^(.*?)(index\.php|$) https://localhost/$1 [R=301,L]

A
AUser0, 2020-03-11
@AUser0

Remove the [L] flag from [R=301,L] - this will cause all applicable rules to fire sequentially.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question