Simple Htaccess Rewriting Issue

Discussion in 'PHP' started by ColorWP.com, Mar 26, 2010.

  1. #1
    Hello.

    How do I send all requests from site.com/dl/Photoshop_8 to site.com/?id=Photoshop_8

    Considering "dl" is a static part of the URL (and it's not an existing directory) and Photoshop_8 is dynamic part of the URL, so it may be something else every time.

    A couple of examples of what the users inputs in his browser and how the htaccess should translate them in the background to the server:

    site.com/dl/Winamp_5 requests go to site.com/?id=Winamp_5
    site.com/dl/Windows_XP requests go to site.com/?id=Windows_XP
    etc...

    The directory /dl/ does not exists on the server, so the virtual URLs won't be conflicting. Also, I am not interested in redirecting the visitor from the virtual URL to the real URL:
    Virtual URL: site.com/dl/Photoshop
    Real URL: site.com/?id=Photoshop
    BUT users entering the Real URL should be redirected to the Virtual URL without creating and endless loop if possible.

    That's it and I'm looking forward for your help. Thanks in advance!
     
    ColorWP.com, Mar 26, 2010 IP
  2. mnvlxxx

    mnvlxxx Peon

    Messages:
    47
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    RewriteEngine on
    RewriteRule ^dl/(.*)$  /?id=$1
    Code (markup):
     
    mnvlxxx, Mar 26, 2010 IP