【问题标题】:Safari removes fragment identifiers when hyperlink is clicked (perhaps .htaccess issue?)单击超链接时,Safari 会删除片段标识符(可能是 .htaccess 问题?)
【发布时间】: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 就术语问题给我打电话。是的,确实我的意思是片段标识符。问题已更新。

标签: php html .htaccess


【解决方案1】:

该示例站点http://www.dentistwoodburymn.com/ 是您正在处理的页面吗?

如果是这样,那你为什么还在你设置的链接中使用.php 扩展名——你不是说你想删除那个扩展名吗(因此你有重写放置,以便/foo 的请求自动重写为/foo.php 内部)...?

替换这种链接

<a href="avi-matha-dds.php#more-about">

<a href="avi-matha-dds#more-about">

– 服务器端重写负责将其指向文件 avi-matha-dds.php 内部 ...以及您的 Safari 问题,这只会发生 因为您的外部重定向.php 到您在此处发布的非.php 版本

# remove .php; use THE_REQUEST to prevent infinite loops
RewriteCond %{THE_REQUEST} ^GET\ (.*)\.php\ HTTP
RewriteRule (.*)\.php$ $1 [R=301]

……也会消失。

【讨论】:

  • 这正是我自己创造的问题,应该已经发现。在第一次设计站点时,我将它托管在一个共享帐户下,因此此时需要 .php。换句话说,我的一个愚蠢的疏忽和你的精彩解释,@CBroe。谢谢。
猜你喜欢
  • 2013-09-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-02-11
  • 2013-01-24
  • 2021-08-18
  • 1970-01-01
相关资源
最近更新 更多