daniel
daniel

Reputation: 1222

mod_rewrite taking over all the links on the page

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

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:


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

Thanks!

Upvotes: 0

Views: 267

Answers (3)

covener
covener

Reputation: 17886

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.

Upvotes: 0

merkuro
merkuro

Reputation: 6177

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.

Upvotes: 0

Blixt
Blixt

Reputation: 50179

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.

Upvotes: 5

Related Questions