重写URL blog.php的/?塞=测试博客博客/测试博客 [英] rewrite url blog.php/?slug=test-blog to blog/test-blog

查看:154
本文介绍了重写URL blog.php的/?塞=测试博客博客/测试博客的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何重写URL blog.php的/?塞=测试博客使用重写规则htaccess的博客/测试博客?

How to rewrite url blog.php/?slug=test-blog to blog/test-blog using rewrite rule in htaccess?

推荐答案

您必须捕获部分在的 的RewriteCond ,并使用了的 重写规则

You must capture part of the query string in a RewriteCond and use that in the 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]

这篇关于重写URL blog.php的/?塞=测试博客博客/测试博客的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆