带 mod_rewrite 的页面锚点?

发布于 2024-07-24 05:36:12 字数 708 浏览 11 评论 0原文

我正在尝试在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

爱已欠费 2024-07-31 05:36:12

实际上,如果您希望生成的 URL 有一个锚点,那么是的,这是可能的。 只是不要忘记在 Apache 配置中,# 标记注释的开始。

如果你想要的是这样的 - 用户输入

http://example.com/page/anchor

and gets redirected to

http://example.com/?p=page#anchor

- 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:

http://example.com/information/faq#foo

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

http://example.com/page/anchor

and gets redirected to

http://example.com/?p=page#anchor

- 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:

http://example.com/information/faq#foo

which are almost what you want, plus they don't mess up caching.

(Whoa, it's midnight already?)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文