问题
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
回答1:
RewriteEngine On
RewriteRule ^([0-9]+)-(.*)$ /post.php?view=$1&title=$2 [QSA,L]
http://www.4webhelp.net/tutorials/misc/mod_rewrite.php
回答2:
This should do:
RewriteEngine On
RewriteRule ^(\d+)-(.*)$ post.php?view=$1&title=$2 [QSA,L]
回答3:
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.
来源:https://stackoverflow.com/questions/4357345/clean-url-using-mod-rewirte