简体   繁体   English

Apache htaccess重写URL规则?

[英]Apache htaccess re-write URL rules?

I want to create URL re-write rules for following URL in htaccess. 我想为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

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. 我尝试了RewriteRule category/([^.]+)/?([^.]+)$ /vedio/category.php?cat=$1&$2 for http://example.com/vedio/category.php?cat=fun&show=popular&page=1但无法正常工作。

Please tell me what could be the correct URL re-write rules for the above requirements? 请告诉我满足上述要求的正确URL重写规则是什么?

The query is not part of the URL path that's checked within the RewriteRule directive. 该查询不是RewriteRule指令中检查的URL路径的一部分。 You would need a RewriteCond directive to do that. 您将需要一个RewriteCond指令来执行此操作。

But you just need to set the QSA flag to get the initial query string appended to the new one: 但是,您只需要设置QSA标志,即可将初始查询字符串附加到新查询字符串之后:

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

My regexp for category script: 我的正则表达式类别脚本:

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

It depends if mod_rewrite is evaluating all your URL (server + port + path) or just the path to your script. 这取决于mod_rewrite是评估您的所有URL(服务器+端口+路径)还是仅评估脚本的路径。

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

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