Flat Links?

Discuss practical ways rearrange URLs using mod_rewrite.

Flat Links?

Postby Mantoos » Tue Sep 16, 2008 1:41 am

Hello =)

I have recently installed a simple blog script on http://www.mydomain.com/blog/

It's programmed with php so if I click on a category it shows http://www.mydomain.com/blog/category.php?cat=3 for instance and when I click on a blog entry i get to http://www.mydomain.com/blog/article.php?id=1 and so on.

Now, since I'm a total htaccess noob I'd like to know if it's possible with mod_rewrite to change the links to something like http://www.mydomain.com/blog/category/categoryname/ (or id if categoryname isn't possible) instead of http://www.mydomain.com/blog/category.php?cat=3

and maybe http://www.mydomain.com/blog/article/articlename/ (or id if articlename isn't possible) instead of http://www.mydomain.com/blog/article.php?id=1

Pretty bad explenation but I hope you understand what I mean=)

Thanks in advance!
Mantoos
 
Posts: 1
Joined: Tue Sep 16, 2008 12:50 am

Postby richardk » Tue Sep 16, 2008 11:47 am

The article/category name is possible, but it isn't as easy. See FAQ: How to change a numeric ID into a name/title.

For the IDs (in /blog/.htaccess)
Code: Select all
Options +FollowSymLinks -MultiViews

RewriteEngine On

RewriteRule ^article/([0-9]+)/?$  ./article.php?id=$1   [QSA,L]
RewriteRule ^category/([0-9]+)/?$ ./category.php?cat=$1 [QSA,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am


Return to Friendly URLs with Mod_Rewrite

Who is online

Users browsing this forum: No registered users and 7 guests

cron