【发布时间】:2014-03-06 20:25:56
【问题描述】:
在我最近的网页设计项目中,我使用a fairly solid technique 从网站页面中删除 .php 文件扩展名。但是,仅在 Safari 中,当用户单击另一个页面的超链接时,此方法现在也会删除片段标识符。这会导致有人转到 .com/example 而不是 .com/example#fradmentidentifier。这是我的 .htaccess 代码:
AddType text/x-component .htc
RewriteEngine On
RewriteBase /
# remove .php; use THE_REQUEST to prevent infinite loops
RewriteCond %{THE_REQUEST} ^GET\ (.*)\.php\ HTTP
RewriteRule (.*)\.php$ $1 [R=301]
# remove index
RewriteRule (.*)/index$ $1/ [R=301]
# remove slash if not directory
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} /$
RewriteRule (.*)/ $1 [R=301]
# add .php to access file, but don't redirect
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteCond %{REQUEST_URI} !/$
RewriteRule (.*) $1\.php [L]
可以在标题为“创造健康美丽的微笑”的侧边栏列表中查看this site 的示例。
我可能弄错了,但我不记得以前遇到过这个问题。知道修复方法吗?
【问题讨论】:
-
锚扩展是什么意思? URL 的一部分,跟在
#? 之后。这部分称为片段标识符。发出请求时,片段标识符永远不会发送到服务器,因此您的.htaccess不是问题的原因。 -
感谢@Oswald 就术语问题给我打电话。是的,确实我的意思是片段标识符。问题已更新。