#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2005
    Location
    Vancouver, WA, USA
    Posts
    398
    Rep Power
    189

    Mod_rewrite regex simplified URL


    I would like to rewrite all of the following:
    domain.com/1234
    domain.com?1234
    domain.com/?1234


    So far I only have domain.com/1234 working:

    Code:
    RewriteBase /
    RewriteRule ^([0-9]+)$ /r.php?ref=$1 [L,R=301]
    Suggestions?
    Thomas Tremain
  2. #2
  3. Transforming Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,191
    Rep Power
    9398
    You cannot rewrite the second since it's an invalid URL.

    As for the third,
    Code:
    RewriteCond %{QUERY_STRING} ^(\d+)$
    RewriteRule ^/?$ r.php?ref=%1 [L,R=301]
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2005
    Location
    Vancouver, WA, USA
    Posts
    398
    Rep Power
    189
    Originally Posted by requinix
    You cannot rewrite the second since it's an invalid URL.
    Strange... The browser seems to know what to do with it..

    Ahh... Looks like the browser automatically converts it to /?1234

    So it looks like I'm covered! Thank you!
    Thomas Tremain

IMN logo majestic logo threadwatch logo seochat tools logo