htaccess does not understand ^www\. rule , if paramters are appended to url

后端 未结 2 1203
青春惊慌失措
青春惊慌失措 2021-01-24 22:39

.htaccess does not understand ^www\\. rule

#do not use this, because i want to redirect from https://www.somedomain.com
#RewriteCond %{HTTPS} off 
         


        
相关标签:
2条回答
  • 2021-01-24 23:03

    You have an additional condition with [OR] that can cause too many redirects. Fix it by using:

    RewriteCond %{HTTPS} off [OR]
    RewriteCond %{HTTP_HOST} ^www\.somedomain\.com$ [NC]
    RewriteRule ^/?$ https://somedomain.com [L,R=301]
    

    Completely clear browser cache before testing this.

    0 讨论(0)
  • 2021-01-24 23:08

    This works will all urls with parameters and without. And it is true, it is very important to clear cache and try to relaod page several times, in several different browsers. Otherwise, some old rules may apply.

    RewriteCond %{HTTPS} off 
    RewriteCond %{HTTP_HOST} ^somedomain\.com$ [OR]
    RewriteCond %{HTTP_HOST} ^www\.somedomain\.com$ [NC]
    RewriteRule ^(.*)$ https://somedomain.com%{REQUEST_URI} [L,NE,R=301]
    

    Results are :

    somedomain.com --> https://somedomain.com

    www.somedomain.com --> https://www.somedomain.com

    somedomain.com/folder/file --> https://somedomain.com/folder/file

    www.somedomain.com/folder/file --> https://www.somedomain.com/folder/file

    TO make things faster:

    DirectoryIndex /index.php
    RewriteEngine On
    RewriteBase /
    
    RewriteCond %{HTTPS} off 
    RewriteCond %{HTTP_HOST} ^typejoy\.biz$ 
    #RewriteCond %{HTTP_HOST} ^typejoy\.biz$ [OR]
    #RewriteCond %{HTTP_HOST} ^www\.typejoy\.biz$ [NC]
    RewriteRule ^(.*)$ https://typejoy.biz%{REQUEST_URI} [L,NE,R=301]
    
    RewriteCond %{HTTPS} off
    RewriteCond %{HTTP_HOST} ^www\.typejoy\.biz$ [NC]
    RewriteRule ^(.*)$ https://typejoy.biz%{REQUEST_URI} [L,NE,R=301]
    
    RewriteCond %{HTTP_HOST} ^www\.typejoy\.biz$ [NC]
    RewriteRule ^(.*)$ https://typejoy.biz%{REQUEST_URI} [L, NE,R=301]
    

    i believe you should not not put L if there are more rules

    0 讨论(0)
提交回复
热议问题