PHP converted to search engine friendly

New to mod_rewrite? This is a good place to start.

PHP converted to search engine friendly

Postby Davo » Fri Sep 12, 2003 5:25 am

Brett or Anyone,

maybe you can help me with my Mod_rewrite problem, I have the following URLs on my site that I would like to make more search Engine friendly

1. http://www.mysite.com/classified.php?choice=top


2. http://www.mysite.com/classified.php?catid=1

3. http://www.mysite.com/classified.php?ca ... ubcatid=85

4. http://www.mysite.com/classified.php?ca ... 87&adid=64


I would like to use .htaccess in my root to change these URLs to be split by a " / " i.e example number 4 would be:

http://www.mysite.com/classified/17/87/64

or to anything that is seach engine friendly but calls the DB......


Can any of you smart colleagues help..I run apache 1.3

I have seen many ways to do this but they do not seem to work I want to use .htaccess alone without any redirection to PHP files or other flat files.



Cheers

David
Davo
 

strating out

Postby grahowler » Sat Sep 20, 2003 3:18 am

Hey David

I only began using mod_rewrite a few months ago and it seems daunting at first but once you get the hang of it it's becomes much easier. I still need to refer a rerence for regular expressions because I forget what all the operators mean. This article is a good guide for that: http://www.phpbuilder.com/columns/dario19990616.php3

Anyway, hopefully this might help...

1. Say you have a url your.url.com/classified/top

then use something like this..

RewriteRule ^classified/([a-zA-Z]+)/?$ classified.php?choice=$1 [L]

For 2. 3. & 4. (your.url.com/classified/17/87/64) you could use something like...

RewriteRule ^classified/([0-9]+)/?([0-9]+)?/?([0-9]+)?/?$ classified.php?catid=$1&subcatid=$2&adid=$3 [L]

Which means: start with classified (^classified/) which will be followed by at least one number, ([0-9]+), that might be followed by a trailing slash, /?, which might be followed by at least one number, ([0-9]+)?, that might be followed by a trailing slash, /?, which might be followed by at least one number and finally a possible trailing slash, ([0-9]+)?/?.

I can't say I am 100% sure on this second one without giving it a run, which I haven't, so sorry if it's not right but hopefully it'll get you started.

Good Luck!
grahowler
 


Return to Beginner's Corner

Who is online

Users browsing this forum: No registered users and 25 guests

cron