Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.htaccess 向slug添加.html扩展名_.htaccess - Fatal编程技术网

.htaccess 向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

在这篇文章中:我得到了99%的解决方案,用于将slug重新写入.html扩展名。 我的问题是,是否也可以
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]
确保在测试之前清除浏览器缓存,并且没有其他规则