I'm trying to rewrite my URL that has two parameters without any luck. When people go to: www.site.com/blog.php?id=421&title=title+of+blog, I want the URL to show: www.site.com/blogposts/421/title+of+blog Here's the code that I'm using: Options +FollowSymLinks RewriteEngine On RewriteRule ^/blogposts/([0-9]+)/([^/\.]+)/?$ /blog.php?id=$1&title=$2 Code (markup): Any help would be greatly appreciated. Thanks.
I also an not a mod_rewrite guru but do check the following links n check which one works for you: http://www.webmaster-toolkit.com/mod_rewrite-rewriterule-generator.shtml http://webmastersresort.com/mod-rewrite-generator/ http://www.thejackol.com/htaccess-cheatsheet/ http://www.generateit.net/mod-rewrite/ http://xem247.com/tool/htaccess.php http://www.webmaster-money.org/tools/htaccess_generator.php http://www.searchenginegenie.com/mod-rewrite-generator.php Code (markup): Document: http://www.workingwith.me.uk/articles/scripting/mod_rewrite Code (markup):
You are welcome tanenqq. Also if you want to read more on mod_rewrite the best book about it that i have read so far is http://www.amazon.com/Definitive-Guide-Apache-mod_rewrite/dp/1590595610 Code (markup): if anybody want to get better understanding of mod_rewrite i would refer this e-book.
Those rules look fine but the leading slash won't work in a .htaccess file. It will only work in an Apache configuration file. If these rules are in a .htaccess file then you will need to remove the leading slash. What that rule does is translates an external visible URL (the one people see in their browsers) of www.site.com/blogposts/421/title+of+blog to an internal URL (the one that your PHP script sees) of www.site.com/blog.php?id=421&title=title+of+blog. If you are requesting www.site.com/blog.php?id=421&title=title+of+blog in your browser then this rule won't do anything. The other problem that could cause this to not work in a .htaccess file is not having AllowOverride All in your Apache config.
Options +FollowSymLinks +Indexes RewriteEngine on RewriteBase / RewriteRule ^blogposts/([^.]+)/([^.]+)$ blog.php?id=$1&title=$2 [L] And the script has to do the title+of+blog part, with some search and replace.