繁体   English   中英

Apache htaccess重写URL规则?

[英]Apache htaccess re-write URL rules?

我想为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 for http://example.com/vedio/category.php?cat=fun&show=popular&page=1但无法正常工作。

请告诉我满足上述要求的正确URL重写规则是什么?

该查询不是RewriteRule指令中检查的URL路径的一部分。 您将需要一个RewriteCond指令来执行此操作。

但是,您只需要设置QSA标志,即可将初始查询字符串附加到新查询字符串之后:

RewriteRule category/([^.]+)/$ /vedio/category.php?cat=$1 [QSA]

我的正则表达式类别脚本:

/vedio/category/([^.]+)/\?([^.]+)$

这取决于mod_rewrite是评估您的所有URL(服务器+端口+路径)还是仅评估脚本的路径。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM