Good 'ol mod rewrite help needed...

Discussion in 'Apache' started by h0ly lag, Oct 27, 2008.

  1. #1
    Ok, first off anyone taking time to read this, thanks. Now what I've made is one of those URL shortening scripts. Like TinyURL. Anyhow, I want to be able to rewrite my URLs like they do.

    The rewrited URL
    domain.com/random-url
    Code (markup):
    to my actual redirect page

    that looks like
    domain.com/redirect.php?url=random-url
    Code (markup):
    It works great other wise. It's just not very clean and short anymore when you have redirect.php?url=bla-bla.
     
    h0ly lag, Oct 27, 2008 IP
  2. Ladadadada

    Ladadadada Peon

    Messages:
    382
    Likes Received:
    36
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Nice and simple:
    RewriteRule (http://.*) /redirect.php?url=$1 [NC]
    Code (markup):
    TinyURL have a slightly different system where they translate a short code into a full URL. For this you need a RewriteRule that looks like this:
    RewriteRule ^/?([a-z0-9]*) /redirect.php?urlcode=$1 [NC]
    Code (markup):
    You also need codes that only contain letters and numbers, a PHP script that will look that urlcode up in a database and redirect you to the proper URL and finally all of the rest of your site must not match the regular expression in that rule. (Anything ending in ".php" would be fine.)
     
    Ladadadada, Oct 27, 2008 IP