0
如何使用htaccess中的重写规则将网址blog.php /?slug = test-blog重写为blog/test-blog?重写url blog.php /?slug =测试博客到博客/测试博客
如何使用htaccess中的重写规则将网址blog.php /?slug = test-blog重写为blog/test-blog?重写url blog.php /?slug =测试博客到博客/测试博客
你必须捕捉查询字符串的一部分在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]
它增加了博客/测试博客?塞=测试博客,并显示未找到404 – 2013-03-15 17:08:16
页@Vicky我忘了附加一个问号'?',看起来你需要两种方式。请参阅最新的答案。 – 2013-03-15 20:13:32
它的工作原理,感谢Olaf。 – 2013-03-16 06:27:14