如何在不改变相对路径的情况下使用 apache's mod_rewrite rewriterule [英] How to use apache's mod_rewrite rewriterule without changing relative paths
问题描述
我在 .htaccess 中有以下重写规则:
I've the following rewrite rule in .htaccess:
RewriteRule ^groups/([^/\.]+)/?$ groupdetail.php?gname=$1 [L,NC]
这需要类似于 www.example.com/groups/groupname 的内容并调用 www.example/groupdetail.php?gname=groupname.它工作得很好.
This takes something like www.example.com/groups/groupname and calls www.example/groupdetail.php?gname=groupname. And it works just fine.
但是 groupdetail.php 上的所有相对链接都使用 groups/作为相对路径,我不希望他们这样做.我如何避免这种情况?
But all the relative links on groupdetail.php use groups/ as the relative path, and I don't want them to. How do I avoid this?
例如,当用户点击 groupdetail.php?gname=groupname 上的链接 <a href="link.php">
时,他会被带到 www.example/groups/链接.php.我想把用户带到 www.example.com/link.php.
For example, when a user clicks on a link <a href="link.php">
on groupdetail.php?gname=groupname, he's taken to www.example/groups/link.php. I want to take the user to www.example.com/link.php.
显然,我希望用户的 URL 看起来像www.example.com/groups/groupname",所以我不想使用 [R]/redirect.
Obviously, I want to URL to the user to look like "www.example.com/groups/groupname" so I don't want to use [R]/redirect.
推荐答案
如果像我一样在页面中有数百个相对链接,请在 带有绝对路径(也可以使用相对路径).您还需要将
中 .js 文件的路径设为绝对路径,因为 IE 和 firefox 处理 base href 的方式不同.我同意这是一个烦人的问题.
If like me you had hundreds of relative links in the page, insert a <base href="">
in the <head>
with an absolute path (could use relative too). You'll need to also make the path to .js files in the <head>
absolute because IE and firefox deal with the base href differently. I agree it is an annoying issue.
这篇关于如何在不改变相对路径的情况下使用 apache&#39;s mod_rewrite rewriterule的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!