带 mod_rewrite 的页面锚点?
我正在尝试在使用 mod_rewrite (在 Ubuntu Server 9.04 上运行的 Apache2)的网站上设置页面锚点。
我的 htaccess 文件如下所示:
RewriteEngine On
RewriteRule ^information.php/([A-Za-z0-9-]+)/?$ information.php?display=$1 [NC,NE]
如果我使用常规 URL,查询将如下所示: http://mydomain/information.php?display=faq#cost
我希望得到这样的结果: http://mydomain/information/faq/cost
这可能吗? 我的理解是 modrewrite 忽略页面锚点,浏览器会处理它? 我猜想我可以以某种方式使用 mod_rewrite 将锚点信息包含在请求中,但我找不到任何记录这一点的信息,并且尝试自己编写几个小时但没有成功。
谢谢!
I'm trying to set up page anchors on a website that uses mod_rewrite (Apache2 running on Ubuntu Server 9.04).
My htaccess file looks like this:
RewriteEngine On
RewriteRule ^information.php/([A-Za-z0-9-]+)/?$ information.php?display=$1 [NC,NE]
If I was using regular URL's the query would look something like this: http://mydomain/information.php?display=faq#cost
I'm hoping to get something like this:
http://mydomain/information/faq/cost
Is this possible? My understanding is that modrewrite ignores page anchors, and that the browser deals with it? I'm guessing that I can somehow use mod_rewrite to include the anchor information with the request, but I haven't been able to find anything documenting this and have been trying unsuccessfully to write it myself for hours.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
实际上,如果您希望生成的 URL 有一个锚点,那么是的,这是可能的。 只是不要忘记在 Apache 配置中,# 标记注释的开始。
如果你想要的是这样的 - 用户输入
and gets redirected to
- you would need to use 301 Redirect, or something like that, so it wouldn't be transparent to the user.
结论:虽然可以编写这样的重定向规则,但不能完全在服务器端完成。 因此,我认为您可以将
/information/faq
指向/information.php?display=faq
,然后使用如下 URL:which are almost what you want, plus they don't mess up caching.
(哇,已经半夜了?)
Actually, if you want the resulting URL to have an anchor, then yes, it's possible. Just don't forget that in Apache configs, # marks the start of a comment.
If what you want is like this - user enters
and gets redirected to
- you would need to use 301 Redirect, or something like that, so it wouldn't be transparent to the user.
Conclusion: While it is possible to write such a redirect rule, it can't be done entirely server-side. So I think you could point
/information/faq
to/information.php?display=faq
and then use URLs such as:which are almost what you want, plus they don't mess up caching.
(Whoa, it's midnight already?)