View Full Version : Dynamic short / search engine friendly URL's

02-01-2009, 07:10 PM

I'd like to use short URL's in my site. I've seen a lot of these online, programs that sort of amalgamate the parts of the long URL e.g. www.mysite.com/interests.php?user_id=12&access=2

What I'd really like, is if I could specify what the short URL should be e.g. myinterests, and that when someone typed in www.mysite.com/myinterests/ it would display the longer URL page (but not redirect them just display it). Is there a way where I can store the short url I'd like to relate to the 'long url' in a database, and when a page in the site is accessed it works out which page to actually display?

I don't know how to go about doing this, but I think it would be really helpful for Yahoo search results, and it looks MUCH nicer for users.

Any ideas? Any tutorials are good too. I've looked through quite a few, but none of them are dynamic i.e. they use htaccess files (which I'm guessing you can't update dynamically using php) to redirect the user to the right page. I'd like something that's completely dynamic.



02-02-2009, 02:33 AM
I am not much of a PHP coder, but, from what I understand, one way to handle this is through modifying your .htaccess file. In ASP.Net (my expertise), you can create a custom HTTP handler to parse and rewrite the URL as needed or use the IIS 7.0 URL Rewrite module. Perhaps there are options like these in the PHP and Linux world?

Hope that helps!

02-02-2009, 07:07 AM
Here is a good tutorial for you!!


02-02-2009, 08:09 AM
Put this in .htaccess

RewriteRule ^interests/([0-9]*).*$ interests.php?user_id=$1

Use this link:

<a href="interests/$RandomUserID">$RandomUsername</a>