如何使用htaccess中的重写规则将url blog.php /?slug = test-blog重写为blog / test-blog?
答案 0 :(得分:2)
您必须在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]