Removing 'index.html' from url and adding 'www' with one single 301 redirect

前端 未结 3 1457
礼貌的吻别
礼貌的吻别 2021-01-06 16:13

In order to remove index.html or index.htm from urls I use the following in my .htaccess

RewriteCond %{REQUEST_URI} /i         


        
3条回答
  •  醉话见心
    2021-01-06 16:49

    Remove the L flag from the prior rule? L forces the rule parsing to stop (when the rule is matched) and thus send the first rewritten URL without applying the second rule.

    The rules are applied sequentially from top to bottom, each rewriting the URL again if it matches the rule's conditions and pattern.

    RewriteCond %{HTTP_HOST} !^www\. [NC]
    RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301]
    
    RewriteRule ^(.*/)index\.html?$ $1 [NC,QSA,R=301,NE,L]
    

    Hence the above will first add the www and then remove the index.html?, before sending the new URL; A single redirect for all the rules.

提交回复
热议问题