如何使用Apache的mod_rewrite重写规则不改变相对路径 [英] How to use apache's mod_rewrite rewriterule without changing relative paths

查看:189
本文介绍了如何使用Apache的mod_rewrite重写规则不改变相对路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在.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 =组名。和它的作品就好了。

This takes something like www.example.com/groups/groupname and calls www.example/groupdetail.php?gname=groupname. And it works just fine.

但是,所有的groupdetail.php使用群体相对链接/作为相对路径,我不希望他们。我该如何避免这种情况?

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?

例如,当用户在链接上点击< A HREF =link.php> 上groupdetail.php的gname =组名,他采取什么? www.example /组/ link.php。我想利用用户www.example.com/link.php~~V。

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] /重定向。

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.

推荐答案

如果你像我一样有数百页的相对链接,插入&LT;基本href =&GT; &LT; HEAD&GT; 使用绝对路径(也可以用相对)。您需要也使路径.js文件中的&LT文件; HEAD&GT; 绝对的,因为IE和Firefox处理基地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的mod_rewrite重写规则不改变相对路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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