Страница 1 из 1

Не работает один редирект в Htaccess, помогите

СообщениеДобавлено: Сб июл 30, 2016 11:19 am
Soldatt
День добрый!

После переезда на новый хостинг, обнаружил, что не работает один редирект " без www http>>www https", все остальные варианты работают.
В файле ничего не менял (кроме заголовка SSL).
Очевидно, что решение простое для специалиста, но не для меня. Кто-то подскажет?
<FilesMatch "\.md5$">
Deny from all
</FilesMatch>

DirectoryIndex index.php
Options -Indexes
# Comment the following line, if option Multiviews not allowed here
# Options -MultiViews

AddDefaultCharset utf-8

<ifModule mod_rewrite.c>
RewriteEngine On
# Uncomment the following line, if you are having trouble
# RewriteBase /

# non-www http >> www https
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^/?(.*) https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]

# www http >> www https
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^/?(.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]

# non-www https >> www https
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP:X-Forwarded-Proto} =https
RewriteRule ^/?(.*) https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]

# www https >> www https
# do nothing

RewriteCond %{HTTP:X-Forwarded-Proto} =http
RewriteCond %{THE_REQUEST} !/robots\.txt [NC]
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [NE,R=301,QSA,L]

# http > https www redirect
RewriteCond %{HTTP_HOST} ^[^.]+\.[^.]+$
RewriteCond %{HTTP:X-Forwarded-Proto} =http
RewriteCond %{THE_REQUEST} !/robots\.txt [NC]
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [NE,R=301,QSA,L]
# http www > https redirect
RewriteCond %{HTTP:X-Forwarded-Proto} =http
RewriteCond %{THE_REQUEST} !/robots\.txt [NC]
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [NE,R=301,QSA,L]

RewriteCond %{REQUEST_URI} !\.(js|css|jpg|jpeg|gif|png)$ [or]
RewriteCond %{REQUEST_URI} apple-touch-icon\.png$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [L,QSA]
</ifModule>

СообщениеДобавлено: Вт авг 02, 2016 2:57 am
Emilien
Потестил эти правила у себя на сервере и ошибок нет, все редиректы работают.
Может не сбрасывали кеш браузера перед проверкой и вам показалось, что редирект не работает.
Если подумать, то эту кучу редиректов можно записать компактнее.
Код: выделить все
RewriteCond %{REQUEST_URI} !^/robots\.txt
RewriteCond %{HTTP_HOST}   !^www\. [NC,OR]
RewriteCond %{HTTP:X-Forwarded-Proto} =http
RewriteRule ^ https://www.site.ru%{REQUEST_URI} [L,R=301,NE]

Вместо site.ru поставить свой домен.


Код: выделить все
<FilesMatch "\.md5$">
Deny from all
</FilesMatch>

DirectoryIndex index.php
Options -Indexes
# Comment the following line, if option Multiviews not allowed here
# Options -MultiViews

AddDefaultCharset utf-8

<ifModule mod_rewrite.c>
RewriteEngine On
# Uncomment the following line, if you are having trouble
# RewriteBase /

RewriteCond %{REQUEST_URI} !^/robots\.txt
RewriteCond %{HTTP_HOST}   !^www\. [NC,OR]
RewriteCond %{HTTP:X-Forwarded-Proto} =http
RewriteRule ^ https://www.site.ru%{REQUEST_URI} [L,R=301,NE]


RewriteCond %{REQUEST_URI} !\.(js|css|jpg|jpeg|gif|png)$ [or]
RewriteCond %{REQUEST_URI} apple-touch-icon\.png$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [L,QSA]
</ifModule>