Search code examples
phpurl-shortener

want to do a simple url shortner


I want to create a simple URL shortner that would do the following:

http://example.com/code

where code would be something like a476u (a random string of letters and numbers). My only problem is reading the code from the url. I want all requests to go to index.php where it would read the url and get the code. But a URL like that would normally point to a folder (where a476u is a folder).

How can I make a request like that go to a file rather then a folder without putting the file name?


Solution

  • Sounds like an .htaccess file to me...

    RewriteRule ([a-zA-Z0-9]{5}) index.php?code=$1
    

    Then, feel free to try it on this site.