clean url using mod_rewirte

前提是你 提交于 2019-12-25 05:32:54

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!