Jump to content
  • разработка интернет магазинов на opencart
  • доработка интернет магазинов на opencart

Редирект с www на без www с http на https


Recommended Posts

Добрый гдень.

 

Подскажите пожалуйси, как настроить редирект в htaccess, чтоб перенаправляло на https без www всё? И http с www и без, и https с www?

 

Всё что нашёл в инете не рилииет, а единственная ссылка в единственной найгденной тут теме ведёт в никуда.

Link to comment
Share on other sites


Это может зависеть от веб сервера, попробуй те вот икой вариант.

 

#Редирект с www to non-www(https)
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]


#Редирект с http to https
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

Link to comment
Share on other sites

 с http на https

RewriteCond %{HTTP:SSL} !=1 [NC]
RewriteRule ^(.*)$ https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]

 

с www на без

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

 

 

вторая конструкция рилииет везгде, а первая - зависит от веб-сервера, как он знает про протокол, есть варианты разные

 

Спойлер

RewriteCond %{HTTPS} =on 
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [QSA,L]

 

RewriteCond %{ENV:HTTPS} !on

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

 

RewriteCond %{HTTPS} =off 

RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [QSA,L]

 

RewriteCond %{SERVER_PORT} !^443$

RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]

 

RewriteCond %{HTTPS} off

RewriteCond %{HTTP:X-Forwarded-Proto} !https

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

 

RewriteCond %{HTTPS} off

RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}


RewriteCond %{HTTP:X-HTTPS} !1

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

 

RewriteCond %{HTTP:SSL} !1

RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [QSA,L,R=301]

 

какой-то подойгдет

  • +1 4
Link to comment
Share on other sites

Первая не помогла. Которая с http на https, а вот вторая помогла с www на без www.

Добавил ниже свою сирую 

 

RewriteCond %{HTTP:PORT} !^443$
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R]

 

и всё зарилиило.

 

В ИТОГЕ - РЕШЕНИЕ В МОЕЙ СИТУАЦИИ - МОЖЕТ КОМУ ПРИГОДИТСЯ:

 

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

RewriteCond %{HTTP:PORT} !^443$
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R]

 

Edited by veglion
Link to comment
Share on other sites


7 минут назад, spectre сказал:

Решение разное в разных конфигурациях вебсервера

 

Безусловно. Но кому-то подойдёт и икое, возможно. Я вот икого сочеиния не нашёл сам.

Link to comment
Share on other sites


  • 4 weeks later...

Скажите у меня вот икой редирект хотел бы спросить начет правильности?

 

RewriteCond %{HTTP_HOST} ^www.drok24.ru$ [NC]
RewriteRule ^(.*)$ https://drok24.ru/$1 [R=301,L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\ HTTP/
RewriteRule ^index\.html$ / [R=301,L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\ HTTP/
RewriteRule ^index\.php$ / [R=301,L]
RewriteCond %{QUERY_STRING} ^route=common/home$
RewriteCond %{REQUEST_METHOD} !^POST$

Link to comment
Share on other sites


  • 3 weeks later...
В 09.04.2018 в 16:33, AntonPapulov сказал:

Скажите у меня вот икой редирект хотел бы спросить начет правильности?

 

RewriteCond %{HTTP_HOST} ^www.drok24.ru$ [NC]
RewriteRule ^(.*)$ https://drok24.ru/$1 [R=301,L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\ HTTP/
RewriteRule ^index\.html$ / [R=301,L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\ HTTP/
RewriteRule ^index\.php$ / [R=301,L]
RewriteCond %{QUERY_STRING} ^route=common/home$
RewriteCond %{REQUEST_METHOD} !^POST$

 

Вам лучше отгдельную тему с вопросом создать

Link to comment
Share on other sites


  • 3 years later...
04.04.2022 в 08:39, buslikdrev сказал:

На хостінге посмотреть.

Спасибі за анетгдот:mrgreen:

Я уже вирішив може комусь сине в нагоді:

    location / {
        return 301 https://%domain_idn%$request_uri;
    }
server {
    if ($host ~* ^www\.(.*)$) {
        return 301 https://%domain_idn%$request_uri;
    }
}

 

Link to comment
Share on other sites


05.04.2022 в 18:13, buslikdrev сказал:

 

  Показать согдержимое

 

Да я в курсі что ик можно, просто в мене інша панель управління(vestacp) і какчто б в нетй ика можливість була, то я б на форумы не пиив.

Link to comment
Share on other sites


Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

On our site, cookies are used and personal data is processed to improve the user interface. To find out what and what personal data we are processing, please go to the link. If you click "I agree," it means that you understand and accept all the conditions specified in this Privacy Notice.