Forum Moderators: coopster

Message Too Old, No Replies

Help with rewriting URLs

php url rewrite

         

gshdesign

7:14 pm on Oct 3, 2004 (gmt 0)



After researching I have found two methods of rewriting URLs.

The apache way with .htaccess and the PHP way with the stargeek function.

I'm having a hard time with getting either method to work.

here is the URL I'm trying to rewrite:
domain.com/cat_display.php?catagory=BOOKS&subcat=SCARY&page=1

I'd like that to look like:
domain.com/cat_display.php/BOOKS/SCARY/1

so basically just convert the? to /

Can someone write the neccesary commands that would go into an .htaccess file for me? Or explain the syntax to me, or give me a link that explains the syntax.

Now to do this with the Stargeek PHP function, I mostly get but I don't understand how to use it exactly. If someone could explain that to me with detail or provide me a link that explains in details, I'd be most appreciative!

Thanks!

davelms

7:36 pm on Oct 3, 2004 (gmt 0)

10+ Year Member



I wanted to do something similar on my site, and went so far as also dropping what you have named "cat_display.php".

There are sme good tutorials out there, but the basic code I used is listed below.

In the past my pages were www.example.com/article/view.php?id=999

But I wanted www.example.com/article/999

I retained view.php but modified it, so that users could come from old links and the new format also.

Additionally, I have a line in .htaccess to invoke view.php on a 404 NOT FOUND (because 999 is neither a file nor a subfolder within article)


.htaccess:
ErrorDocument 404 /article/view.php

PHP:
$uri = $_SERVER['REQUEST_URI'];
$uri_array = explode("/",$uri);
$article_id = (integer) $uri_array[2];

In my case, $article_id now contains 999 and I can do with it what I did before.

I have further pages that accept more than one "variable", and have made them work as a variation on the above.

Adrian2k4

1:03 am on Oct 4, 2004 (gmt 0)

10+ Year Member



try the apache module "mod_rewrite":
[httpd.apache.org...]

it's made for exectly that: url rewriting...

neo_brown

11:24 am on Oct 4, 2004 (gmt 0)

10+ Year Member



You can also find some generators that will do it all for you. You enter your URL, it gives you an SE friendly version and the neccesary data for htaccess.
Just do a search on google and you will find it on some of the well known webmaster resource tyep sites.