.htaccess 向slug添加.html扩展名
在这篇文章中:我得到了99%的解决方案,用于将slug重新写入.html扩展名。 我的问题是,是否也可以.htaccess 向slug添加.html扩展名,.htaccess,.htaccess,在这篇文章中:我得到了99%的解决方案,用于将slug重新写入.html扩展名。 我的问题是,是否也可以 http://domain.com 动态的 index.php可能在子目录(即test/index.php)上运行,也可能没有 上述职位上的代码为: RewriteEngine on Options +FollowSymLinks RewriteCond %{SCRIPT_FILENAME} !-f RewriteCond %{SCRIPT_FILENAME} !-d RewriteCond
http://domain.com
动态的
index.php可能在子目录(即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}似乎不起作用。这应该通过从目标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]
确保在测试之前清除浏览器缓存,并且没有其他规则