August 30, 2013

Shortened url redirect?

Huyimin’s Question:

I need help to get this done.

My webpages have formatted urls in this pattern: “http://qifu.us/index.php?page=item&id=4” for example – if there are more pages, only the last page id number will be different.

I want to get this part “index.php?page=item&id=” out, and shortened like “http://qifu.us/s4“, when a user input the shortened url into to address bar, it will be directed to the right page, which is the true url.

I am thinking to save the STATIC part “index.php?page=item&id=” into a string variable, and append the DYNAMIC page id – which is 4 in this example, then use Javascript or PHP to direct to the right page. But I don’t know how the steps, pls help. Thanks.

Actually an htaccess will be very good for this purpose.

For urls like http://qifu.us/s4 do the following: Create a file with name .htaccess and place at your root directory with the following content.

RewriteEngine On
RewriteRule ^s([^/]*)$ /index.php?page=item&id=$1 [L]

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+

...

Please fill the form - I will response as fast as I can!