【问题标题】:Add .html extension to slug将 .html 扩展名添加到 slug
【发布时间】:2015-05-11 06:34:32
【问题描述】:

在这篇文章中:htaccess add .html extension for urls with or without trailing slash 我得到了 99% 的将 slug 重写为 .html 扩展名的解决方案。 我的问题是,是否也可以使 http://domain.com 动态的?

index.php 可能会或可能不会在子目录(IE.test/index.php)上运行。

提到的帖子上的代码是:

RewriteEngine on
Options +FollowSymLinks
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-l
RewriteRule ^(([\w/-]+)?[\w-])/?(?!:\.html)$ http://domain.com/$1.html [L,R=301]
RewriteRule ^(([\w/-]+)?[\w-])\.html$ test/index.php?slug=$1 [L]

PS:%{HTTP_HOST} 似乎无法解决问题。

【问题讨论】:

    标签: .htaccess


    【解决方案1】:

    这应该通过从目标 URI 中删除主机部分来工作:

    RewriteCond %{SCRIPT_FILENAME} !-f
    RewriteCond %{SCRIPT_FILENAME} !-d
    RewriteCond %{SCRIPT_FILENAME} !-l
    RewriteRule ^(([\w/-]+)?[\w-])/?(?!:\.html)$ /$1.html [L,R=302,NC]
    
    RewriteRule ^(([\w/-]+)?[\w-])\.html$ admin/index.php?slug=$1 [L,QSA,NC]
    

    确保在测试之前清除浏览器缓存,并且没有其他规则。

    【讨论】:

      猜你喜欢
      • 2020-07-23
      • 1970-01-01
      • 2014-09-06
      • 1970-01-01
      • 1970-01-01
      • 2011-08-10
      • 2013-02-11
      • 2010-10-23
      • 1970-01-01
      相关资源
      最近更新 更多