Shorten URL for listing

They have: 42 posts

Joined: Dec 2002

Hello All,

Does anyone know of any easy way, either through a script or through htaccess to shorten a url link?

currently the link looks like this:
http://www.mysite.com/listingview.php?listingID=17

I want to shorten it to something like:
http://www.mysite.com/listingID=17

Any suggestions?

NYColt

He has: 10 posts

Joined: Mar 2004

Please be more elaborate....

They have: 42 posts

Joined: Dec 2002

Well,

I have a website where customers place ads.

The actual link from within the website would be, as an example:http://www.mysite.com/listingview.php?listingID=17
or
http://www.mysite.com/listingview.php?listingID=18
and so on....

I would like to shorten the link to something like:
http://www.mysite.com/listingID=17

So that if the advertiser has a newspaper ad they can include the simple internet link http://www.mysite.com/listingID=17 in the add rather than
the more difficult:
http://www.mysite.com/listingview.php?listingID=17

Does that make sense?

NYColt

He has: 1,758 posts

Joined: Jul 2002

If you use Unix/Linux hosting you could use mod rewrite to redirect to make the url look something like

http://www.mysite.com/listing/17

You would need to add something like this to either your httpd.conf or a .htaccess file

RewriteRule ^/listing/\([0-9]{1,4})$ /listingview.php?newsID=$1 [L]'

I think that should work. Can't promise you though... its not really one of my specialities. Wink

Andy

They have: 42 posts

Joined: Dec 2002

great I will try that and let you know how it works

They have: 42 posts

Joined: Dec 2002

I added the code to a .htaccess file but I get a "page cannot be found" message.

They have: 42 posts

Joined: Dec 2002

Hello Andy,

I got this to work great.

RewriteCond %{REQUEST_URI} ^/([0-9]+)$
RewriteRule ^(.*) /listingview.php?listingID=%1 [L,R]

This produces this:

http://www.mysite.com/17 or another variable

Very Simple and clean, just what I needed!

Hope this thread helps someone else down the trail!

Thanks for the look and see and input on this issue.

NYColt

He has: 1,758 posts

Joined: Jul 2002

Congratulations! I hope it helps people as well, cos it took me absolutly ages to get my head round it when I first wanted to use it!

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.