clean url using mod_rewirte
How i can convert this url
www.domain.com/post.php?view=36&title=slug-of-post-title
into clean url as
www.domain.com/36-slug-of-post-title
Help me, if you know where i can get a better understanding about mod_rewrite please provide开发者_开发知识库 website address
thanks
RewriteEngine On
RewriteRule ^([0-9]+)-(.*)$ /post.php?view=$1&title=$2 [QSA,L]
http://www.4webhelp.net/tutorials/misc/mod_rewrite.php
This should do:
RewriteEngine On
RewriteRule ^(\d+)-(.*)$ post.php?view=$1&title=$2 [QSA,L]
mod_rewrite
is a feature of Apache. Similar modules exist for other web servers such as lighttpd, nginx, tornado, etc. As usual, RTM applies here:
http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html
For the URL you asked about, you may want to do something like this:
RewriteEngine On
RewriteBase /
# now the rewriting rules
RewriteRule ^([0-9]+)-(.*)$ post.php?view=$1&title=$2 [QSA,L]
What the rule above does is match any URL in your domain starting with / (see RewriteBase
), followed by at least one digit (([0-9]+)
), followed by anything, to the appropriate place.
Please see the link above for more information about mod_rewrite.
精彩评论