Apache htaccess重写URL规则?
我想为 htaccess 中的以下 URL 创建 URL 重写规则。
http://example.com/vedios/category/fun/ -> http://example.com/vedios/category.php?cat=fun
http://example.com/vedios/category/fun/?show=popular -> http://example.com/vedios/category.php?cat=comedy&show=popular
http://example.com/vedios/category/fun/?show=popular&page=2 -> http://example.com/vedios/category.php?cat=comedy&show=popular&page=2
http://example.com/vedios/category/fun/comedy/ -> http://example.com/vedios/category.php?cat=comedy
http://example.com/vedios/category/fun/comedy/?show=popular -> http://example.com/vedios/category.php?cat=comedy&show=popular
http://example.com/vedios/category/fun/comedy/?show=popular&page=3 -> http://example.com/vedios/category.php?cat=comedy&show=popular&page=3
我尝试了 RewriteRule Category/([^.]+)/?([^.]+)$ /vedio/category.php?cat=$1&$2
为 http:// example.com/vedio/category.php?cat=fun&show=popular&page=1
但它不起作用。
请告诉我对于上述要求正确的 URL 重写规则是什么?
I want to create URL re-write rules for following URL in htaccess.
http://example.com/vedios/category/fun/ -> http://example.com/vedios/category.php?cat=fun
http://example.com/vedios/category/fun/?show=popular -> http://example.com/vedios/category.php?cat=comedy&show=popular
http://example.com/vedios/category/fun/?show=popular&page=2 -> http://example.com/vedios/category.php?cat=comedy&show=popular&page=2
http://example.com/vedios/category/fun/comedy/ -> http://example.com/vedios/category.php?cat=comedy
http://example.com/vedios/category/fun/comedy/?show=popular -> http://example.com/vedios/category.php?cat=comedy&show=popular
http://example.com/vedios/category/fun/comedy/?show=popular&page=3 -> http://example.com/vedios/category.php?cat=comedy&show=popular&page=3
I tried RewriteRule category/([^.]+)/?([^.]+)$ /vedio/category.php?cat=$1&$2
for http://example.com/vedio/category.php?cat=fun&show=popular&page=1
but its not working.
Please tell me what could be the correct URL re-write rules for the above requirements?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
该查询不是
RewriteRule
指令中检查的 URL 路径的一部分。 您需要一个RewriteCond
指令来执行此操作。但您只需设置 QSA 标志 即可获取初始查询字符串附加到新查询字符串后:
The query is not part of the URL path that’s checked within the
RewriteRule
directive. You would need aRewriteCond
directive to do that.But you just need to set the QSA flag to get the initial query string appended to the new one:
我的类别脚本正则表达式:
这取决于 mod_rewrite 是否正在评估您的所有 URL(服务器 + 端口 + 路径)或仅评估脚本的路径。
My regexp for category script:
It depends if mod_rewrite is evaluating all your URL (server + port + path) or just the path to your script.