重写url blog.php /?slug = test-blog到blog / test-blog

时间:2013-03-15 11:39:16

标签: .htaccess url-rewriting rewrite

如何使用htaccess中的重写规则将url blog.php /?slug = test-blog重写为blog / test-blog?

1 个答案:

答案 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]
相关问题