.htaccess 中的 mod_rewrite
大家好,我怎样才能减少这个:
www.example.com/index.php?page=viewblog&category=awesome
归结为:
www.example.com/blog/awesome
上面列出了该类别中的所有博客文章,但我也希望在其末尾添加帖子标题,如下所示
www.example.com/index.php?page=viewblog&category=awesome&post=why-trees-are-green
:需要缩短为:
www.example.com/blog/awesome/why-trees-are-green
有什么想法吗?提前致谢 :)
Hey all, how can I reduce this:
www.example.com/index.php?page=viewblog&category=awesome
down to this:
www.example.com/blog/awesome
The above lists all of the blog posts in that category, but I also want scope for adding the title of the post on the end of it as well, like this:
www.example.com/index.php?page=viewblog&category=awesome&post=why-trees-are-green
And this needs to shorten down to:
www.example.com/blog/awesome/why-trees-are-green
Any ideas, anyone? Thanks in advance :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
该条件确保请求的 URL 不是您想要提供的实际文件(css、图像等)
然后,每个级别一个规则,第一个规则将重写
http://yourserver.com/blog/whatever
到http://yourserver.com/index.php?page=viewblog&category=whatever
第二个将重写
http://yourserver.com/blog/whatever/whenever
> 到http://yourserver.com/index.php?page=viewblog&category=whatever&post=whenever
如果您需要更多级别,请相应地添加更多规则。
The condition makes sure the requested URL is not an actual file, which you want to serve (css, images, etc.)
Then, one rule per level, the first one will rewrite
http://yourserver.com/blog/whatever
tohttp://yourserver.com/index.php?page=viewblog&category=whatever
The second one will rewrite
http://yourserver.com/blog/whatever/whenever
tohttp://yourserver.com/index.php?page=viewblog&category=whatever&post=whenever
If you need more levels, add more rules accordingly.
像这样的东西吗?
Something like this?