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

后端 未结 2 1222
青春惊慌失措
青春惊慌失措 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: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

提交回复
热议问题