Forum Moderators: phranque

Message Too Old, No Replies

How To Shorten URLs

         

NYColt

8:24 pm on Mar 6, 2004 (gmt 0)

10+ Year Member


Hello everyone,

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 automatically

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? Is this possible using a script, php, or htaccess?

NYColt

NYColt

8:27 pm on Mar 6, 2004 (gmt 0)

10+ Year Member



Someone else has suggested this:
RewriteRule ^/listing/\([0-9]{1,4})$ /listing.php?newsID=$1 [L]

But it does not work as is and appears incomplete to me?

Thanks
NYColt

jonknee

9:32 pm on Mar 6, 2004 (gmt 0)

10+ Year Member



I would go for an even nicer URL:

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

If memory serves, this will work:


RewriteBase /
RewriteRule ^listing/([0-9]+) listing.php?newsID=$1

NYColt

10:01 pm on Mar 6, 2004 (gmt 0)

10+ Year Member



Hello Jonknee

That did not work.
Would I call it like this: [listing.mysite.com...]

I have some sub domains in my htaccess too.

This is what I have now. Does this look like it should work?:

RewriteEngine On
Options +FollowSymlinks
RewriteBase /
RewriteCond %{HTTP_HOST} nycapital.mysite.com
RewriteCond %{REQUEST_URI}!nycapital/
RewriteRule ^(.*)$ nycapital/$1 [L]
RewriteCond %{HTTP_HOST} tampa.mysite.com
RewriteCond %{REQUEST_URI}!tampa/
RewriteBase /
RewriteRule ^listing/([0-9]+) listing.php?newsID=$1

jonknee

12:26 am on Mar 7, 2004 (gmt 0)

10+ Year Member



You don't need the RewriteBase twice. I haven't done mod_rewrite with subdomains, there may be something else you need to do.

NYColt

12:49 pm on Mar 7, 2004 (gmt 0)

10+ Year Member



sorry made a mistake on my earlier post. I am NOT trying to do this with a subdomain but from

[mysite.com...]

I was just trying to show that I do have other rewrite rules in my htaccess file. is that ok?

Is there anything else I should need to do to get this to work other than add that line of code to my htaccess file? Like do I need to to create a directory called Listing or anything like that? Also my htaccess should be in my httdocs correct?

Thanks
NYColt

NYColt

2:07 pm on Mar 7, 2004 (gmt 0)

10+ Year Member



Hi All

Got this to work.

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

which works with:

[mysite...]

VERY easy!

Thanks for the look and see on this issue.
Hope the thread can help someone else down the road.

NYColt