tags:

views:

24

answers:

1

I need to take a url, "/ServiceSearch/r.php?n=blahblah", and have it go to "/search/blahblah/" so that it appears in the browser as "/search/blahblah", but I actually want it to REALLY be going to "r.php?n=ServiceSearch&n=blahblah"..

So I was thinking I'll need to rewrite the first URL to "/ServiceSearch/r.php?n=blahblah" and then the second url, "/search/blahblah/", to the third, "r.php?n=ServiceSearch&n=blahblah".

Well, I know this is wrong, but it's my best guess. I'm really struggling with it.

+1  A: 

Well, I know this is wrong

No, that’s actually the right way. Something like the following should work:

RewriteRule /ServiceSearch/r.php?n=(.*)$ /search/$1 [R]
RewriteRule /search/(.*)$ /r.php?n=ServiceSearch&n=$1 [L]

Here, (.*) captures the variable part (“blablabla”) and inserts it into the replacement via $1. The flags at the end mean that the first query should be a HTTP redirect ([R]), i.e. the client’s browser will be instructed to redirect to that address. And that the second redirect is to be the last ([L] – it’s also not an HTTP redirect since we didn’t specify that; instead, the redirect is handled on the server side). Strictly speaking, the [L] flag isn’t necessary but if you later add more rewrite rules it will prevent unwanted interference.

Konrad Rudolph
Matthew Haworth
Argh, comments don't allow line breaks : [
Matthew Haworth
Konrad Rudolph
Thanks a lot for your help : ].It's still not moving the page : /. I imagine it's something on my end that I'm doing silly.. I don't have to put the full URL in do I?
Matthew Haworth
Try putting the full URL in. It shouldn’t be necessary but I may be wrong. Also, did you enable the rewrite engine? (`RewriteEngine on`).
Konrad Rudolph
Matthew Haworth