mod_rewrite接管页面上的所有链接

时间:2021-12-28 08:35:38

I've used mod_rewrite to rewrite links on my site like so:

我已经使用mod_rewrite重写我网站上的链接,如下所示:

mysite.com/store/<store_id>/<store_name>/<page>
mysite.com/store.php?id=<store_id>&page=<page>

for example:

mysite.com/store/1313/johnny-walker-inc/13
mysite.com/store.php?id=1313&page=13

However, as a result, all my links that we're relationally placed now start at the end of the link, for example:

但是,因此,我们现在关联的所有链接都从链接的末尾开始,例如:

mysite.com/send_message.php

has become

mysite.com/store/1313/johnny-walker-inc/send_message.php

How can I fix this?

我怎样才能解决这个问题?

Here is my mod_rewrite code, in case I'm making a mistake with it:

这是我的mod_rewrite代码,以防我犯了错误:


RewriteRule ^store/([0-9]+)/[^/]+/([0-9]+)$ store.php?storeid=$1&page=$2 [L]

Thanks!

3 个解决方案

#1


You need to make your links relative to the root, like so:

您需要建立相对于根的链接,如下所示:

<a href="/send_message.php">link</a>

Note the slash before send_message.php.

请注意send_message.php之前的斜杠。

#2


I personally only see one solution: Just make all your links absolute. It's not directly a problem with mod_rewrite, but the browsers way of interpreting these links. From their perspective you have a directory structure and they interpret the relative position accordingly.

我个人只看到一个解决方案:只是让你所有的链接绝对。这不是mod_rewrite的直接问题,而是浏览器解释这些链接的方式。从他们的角度来看,你有一个目录结构,他们相应地解释相对位置。

#3


Other solutions include a BASE href or just rewriting all the page elements that can be referenced by the imaginary context root you're showing the client.

其他解决方案包括BASE href或只是重写可以由您显示客户端的虚构上下文根引用的所有页面元素。

#1


You need to make your links relative to the root, like so:

您需要建立相对于根的链接,如下所示:

<a href="/send_message.php">link</a>

Note the slash before send_message.php.

请注意send_message.php之前的斜杠。

#2


I personally only see one solution: Just make all your links absolute. It's not directly a problem with mod_rewrite, but the browsers way of interpreting these links. From their perspective you have a directory structure and they interpret the relative position accordingly.

我个人只看到一个解决方案:只是让你所有的链接绝对。这不是mod_rewrite的直接问题,而是浏览器解释这些链接的方式。从他们的角度来看,你有一个目录结构,他们相应地解释相对位置。

#3


Other solutions include a BASE href or just rewriting all the page elements that can be referenced by the imaginary context root you're showing the client.

其他解决方案包括BASE href或只是重写可以由您显示客户端的虚构上下文根引用的所有页面元素。