View Full Version : Rewriting URL's with mod_rewrite

01-24-2005, 09:53 PM
I've got this code:

RewriteEngine on
Options +FollowSymlinks
RewriteBase /
RewriteRule ^displayimage$ $1displayimage.php$2 [R]

Is this the correct code if I want to chnage the URL like so:

From: http://www.mydomain.com/displayimage.php?id=54&name=image.jpg

To: http://www.mydomain.com/displayimage?id=54&name=image.jpg

Seems to work fine but I end up with two forward slashes after the domain name.

Any help?


02-08-2005, 02:56 AM
I'm guessing because you aren't matching anything with regex, therefore $1 and $2 are empty

Try this:

RewriteRule ^displayimage?(.*)$ /displayimage.php?$1

Also, you don't have to put the [R] in, as this is redirect. If you're trying to hide the .php url from the user leave it out completely otherwise you'll get a 302 (i think) redirect and the user will see the .php url (I could have really explained this better)

Let me try again, without [R] the redirect is done by apache behind the scenes.
With the [R] the redirect is done in the browser