如何使用 htaccess 中的重写规则将 url blog.php/?slug=test-blog 重写为 blog/test-blog?
问问题
747 次
1 回答
2
您必须在 a 中捕获部分查询字符串RewriteCond
并在RewriteRule
RewriteEngine on
# prevent endless loop
RewriteCond %{ENV:REDIRECT_STATUS} 200
RewriteRule ^ - [L]
# redirect to pretty url
RewriteCond %{QUERY_STRING} slug=(.+)
RewriteRule ^blog.php$ /blog/%1? [R,L]
# serve real content
RewriteRule ^blog/(.+)$ /blog.php?slug=$1 [L]
于 2013-03-15T15:31:40.167 回答