Forum Moderators: coopster
I'm trying to create search engine friendly urls for my site. The site structure looks something like this:
Category1
-Article1
-Article2
-Product1
-Sub-catetory
--Article3
--Article4
--Product2
--Quiz1
Category2
-Article5
-Quiz2
Basically, there are 2 levels of categories and there can be an Article, a Product or a Quiz at any level.
I need the URLs to look like folders.
mysite.com/category1/category2/article1/
mysite.com/category1/quiz2/
mysite.com/category1/category2/product2/
what i'm thinking to do is to pick the last bit from the url and search in the DB tables with the item name to identify if its an Article, a product, a quiz or just a sub category. obviously in this case i'll have to define unique names for all items and it also means that before displaying the page i'll have to query the DB 4 times jus to find out the type of item.
Could anyone suggest a better solution to this problem. I'ev read the forum but couldnt find any solution.
Many Thanks.
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{REQUEST_FILENAME}!-f
RewriteCond %{REQUEST_FILENAME}!-d
RewriteRule .* /index.php [L]
This will divert anything that isn't an existing file or directory to the index.php file which then splits the URI into parts for navigation.
The category thing you mentioned is something that I've had to deal with before. Someone else has mentioned on the forums the 'modified pre-order tree traversal' method. Basically it allows you to find a path to a node (category), or the children of a node using one single database query. Try googling it, I know sitepoint has a great article on how to use it.
first of all thanks for taking the time to reply...I have used this code in the htaccess file but it doesnt seem to be working. I am using Apache 1.3.3 with PHP 4.3.10.
I get an "Internal Server Error" when ever i try to access any file from the directory.
I didnt know this whole search engine friendly url thing would be this big of a problem...:(..Please Help!
Thanks
zeeshan
Added: Looking at your question again, I see you want to do the work in php. If you don't manage to do it you can always fall back on mod_rewrite.
Just take it slowly and carefully, many people have done what you are trying to do.