【问题标题】:Combine several rules into one redirect Apache .htaccess将多个规则合并为一个重定向 Apache .htaccess
【发布时间】:2019-05-15 23:36:08
【问题描述】:

我的 .htaccess 文件中有两条规则,第一条是将 http 重定向到 https,第二条是清理 url。

是否有可能以某种方式将它们结合起来以减少对最终用户的重定向?

// http to https
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteRule ^ https://examplename.com%{REQUEST_URI} [L,NE,R=301]

// clean url
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*\.html\ HTTP/
RewriteRule ^(.*)\.html$ /$1 [R=301,L]

【问题讨论】:

    标签: apache .htaccess


    【解决方案1】:

    检查这个组合规则:

    RewriteEngine On
    RewriteCond %{HTTPS} off [OR]
    RewriteCond %{HTTP_HOST} ^www\. [NC]
    RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*\.html\ HTTP/
    RewriteRule ^(.*)\.html$ https://examplename.com/$1 [L,NE,R=301]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-10-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多