M
M
Max2019-07-20 17:49:46
htaccess
Max, 2019-07-20 17:49:46

How to make a correct redirect to https://site.ru?

It is required to make a redirect, in one go to https://site.ru from all possible options:
site.ru
www.site.ru
site.ru/index.php
www.site.ru/index.php
www.site.ru
etc.
I currently have this:

RewriteEngine On
    RewriteCond %{SERVER_PORT} !^443$
    RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]
    RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\ HTTP/
    RewriteRule ^index\.php$ https://site.ru/ [R=301,L]

But there are extra redirects, for example:
site.ru
https://site.ru/index.php
https://site.ru/

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
dodo512, 2019-07-20
@jjsf

RewriteEngine On

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

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question