带有 mod_rewrite 的页面锚点? [英] Page anchor with mod_rewrite?

查看:28
本文介绍了带有 mod_rewrite 的页面锚点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在使用 mod_rewrite(在 Ubuntu Server 9.04 上运行的 Apache2)的网站上设置页面锚点.

I'm trying to set up page anchors on a website that uses mod_rewrite (Apache2 running on Ubuntu Server 9.04).

我的 htaccess 文件如下所示:

My htaccess file looks like this:

RewriteEngine On
RewriteRule ^information.php/([A-Za-z0-9-]+)/?$ information.php?display=$1  [NC,NE]

如果我使用常规 URL,查询将如下所示:http://mydomain/information.php?display=faq#cost

If I was using regular URL's the query would look something like this: http://mydomain/information.php?display=faq#cost

我希望得到这样的东西:http://mydomain/information/faq/cost

I'm hoping to get something like this: http://mydomain/information/faq/cost

这可能吗?我的理解是 modrewrite 忽略页面锚点,而浏览器会处理它?我猜我可以以某种方式使用 mod_rewrite 将锚信息包含在请求中,但我一直无法找到任何记录此内容的内容,并且一直尝试自己编写它几个小时都没有成功.

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.

谢谢!

推荐答案

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

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

并被重定向到

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

- 你需要使用 301 Redirect 或类似的东西,所以它不会对用户透明.

- 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,然后使用诸如:

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.

(哇,已经半夜了?)

这篇关于带有 mod_rewrite 的页面锚点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆