Forum Moderators: coopster

Message Too Old, No Replies

Clean URLS

         

hswaseer

7:40 am on Apr 9, 2005 (gmt 0)

10+ Year Member



Hi,

I am able to clean my following URL
www.example.com/?category_id=100

INTO
www.example.com/index/100

IS it possible to convert this url into
www.example.com/100

Thanks
HS

IamStang

1:56 pm on Apr 9, 2005 (gmt 0)

10+ Year Member



Try reading up on str_replace in the manual. It may be what you need.

[us3.php.net...]

IamStang

ergophobe

8:43 pm on Apr 12, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Let's say category #100 is "My Cat"

Then you would want to clean the URL up to be something like

www.example.com/category/100/
www.example.com/category/My_Cat/

Assuming that you might have places to go other than categories, like articles or images or threads or posts or whatever.

If you don't, that is everything coming to your site is IDed by a category id, then you could do

www.example.com/100/
www.example.com/My_Cat/

This:
www.example.com/index/100

The /index part there really isn't necessary.

jusdrum

10:58 pm on Apr 12, 2005 (gmt 0)

10+ Year Member



If you are using Apache and MultiViews are on, you can refer to php files just by name (without the extension). For instance:

http://www.example.com/products.php

Can be accessed as:

http://www.example.com/products

Now, you can do nice URLs like:

http://www.example.com/products/category/product-name

To access the items after products, parse $_SERVER['PATH_INFO']. I usually do this:

$Parts = explode("/",$_SERVER['PATH_INFO']);

Then iterate through that array and use the the data. Also be warned that explode will assign $Parts[0] an empty value, since $_SERVER['PATH_INFO'] starts with a slash. A quick way around that is the replace the first slash with nothing:

$PathInfo = preg_replace("#^[/]#","",$_SERVER['PATH_INFO']);

Then explode it.

Hope this helps!