你好,我的网站上有一个 anchor 。通过调用我的站点,url 将是:
http://site.com/page.php
通过点击一个按钮,url 将显示一个我想隐藏的 url:
http://site.com/page.php#1
现在我发现我可以使用 mod_rewrite 工具来改变它。我尝试了这条规则但没有成功:
重写引擎开启
RewriteCond %{REQUEST_URI} ^(.*)\.html$
RewriteRule ^.*\.html$ %1.php [L]
用于将页面调用为 html 或 php 并将 #1
隐藏在 .php 后面
RewriteRule ^(.*)$ ./php#1=php$1
如果有人可以就如何解决这个问题给我建议,我将不胜感激。非常感谢。
最佳答案
您不能通过 mod_rewrite 实现此目的。
#
之后的 URL 不通过服务器传递。
如果您仍想实现此目的,您可能需要考虑通过 JavaScript 实现:
<a href="#checkthisout" onclick="scrollHere">Check this out</a>
JavaScript:
function scrollHere() {
// Scroll to the anchor
//(you may need to look for some script to achieve this)
return false; // to prevent URL overwriting
}
一个这样的脚本是 jQuery.scrollTo .
关于php - mod_rewrite 重写规则?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11629386/