Forum Moderators: coopster

Message Too Old, No Replies

Using PHP instead of mod_rewrite to rewrite URLs

... how to?

         

le_gber

4:37 pm on Jun 16, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi all,

I want to create a directory with search engine friendly URL and did some searching on the net.

I was aware of the mod_rewrite solution but cam accross some PHP solutions that look interesting.

q1: What are the advantage of using one method over the other?

In my case (two variables - less than 1000 pages) it would be a combination of explode(), PATH_INFO and a switch statement (to assign the proper (key)word to the id's).

q2: Anyone know of a complete tutorial on how to achieve this?

Thanks

alce

5:11 pm on Jun 16, 2006 (gmt 0)

10+ Year Member



Hi le_gber,

To me, using mod_rewrite is the way to go. I am not familiar with the PHP solution but it sounds a bit more involved.

Using mod_rewrite is relatively easy. The biggest challenge is understanding regular expressions but you can always ask for a bit of help.

barns101

6:17 pm on Jun 16, 2006 (gmt 0)

10+ Year Member



Yes, go for mod_rewrite. I use that for a pub and a restaurant directory that I set up (e.g. http://www.example.com/city-centre/la-trattoria/)

The directories don't exist and a combination of mod_rewrite and explode("/",$_SERVER[REQUEST_URI]); gets the job done to lookup the listing from a MySQL database.

le_gber

8:00 am on Jun 19, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



ok mod_rewrite seem to be the solutions then - anyone using the PHP one?

barns101

12:10 pm on Jun 19, 2006 (gmt 0)

10+ Year Member



How does it work using PHP alone? If the directory structure doesn't actually exist, you'll get a 404 error served by default unless you use mod_rewrite.

jdMorgan

12:57 pm on Jun 19, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Here's an introductory WebmasterWorld library post on using Apache mod_rewrite for this purpose:

Changing dynamic to static URLs [webmasterworld.com] - A basic introduction to using mod_rewrite on Apache server to implement search-engine-friendly static URLs on dynamically-generated sites.

Jim

le_gber

2:38 pm on Jun 19, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



brns101 try googling for 'php friendly urls' you will see tutorials.

jdMorgan, thanks for the link - I read about RewriteMapping - this sound like a winner :)

barns101

10:58 am on Jun 20, 2006 (gmt 0)

10+ Year Member



Ah yes, I remember reading about the www.example.com/script.php/foo/bar method when I was looking into making dynamic URLs appear static. Go for mod_rewrite! ;)