Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Apr 2004
    Posts
    684
    Thanks
    24
    Thanked 1 Time in 1 Post

    Rewriting URL's with mod_rewrite

    I've got this code:

    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?

    Thanks!

  • #2
    Regular Coder
    Join Date
    Feb 2005
    Location
    UK
    Posts
    133
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •