页面锚mod_rewrite的? [英] Page anchor with mod_rewrite?
问题描述
我试图设置页面的锚使用mod_rewrite的网站上(Apache2的Ubuntu服务器9.04上运行)。
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 /信息/ FAQ /成本
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.
谢谢!
推荐答案
其实,如果你想在结果 URL有一个锚,那么是的,这是可能的。只是不要忘记,在Apache的CONFIGS,#标记注释的开始。
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重定向,或者类似的东西,所以它不会对用户透明。
- you would need to use 301 Redirect, or something like that, so it wouldn't be transparent to the user.
结论:虽然可以写这样的重定向规则,它不能做到完全的服务器端。所以我觉得你可以点 /信息/常见问题解答
到 /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.
(哇,这是午夜了吗?)
(Whoa, it's midnight already?)
这篇关于页面锚mod_rewrite的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!