Apache htaccess重写URL规则?

发布于 2024-07-26 00:28:16 字数 1066 浏览 12 评论 0原文

我想为 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&$2http:// 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

风月客 2024-08-02 00:28:17

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

但您只需设置 QSA 标志 即可获取初始查询字符串附加到新查询字符串后:

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

The query is not part of the URL path that’s checked within the RewriteRule directive. You would need a RewriteCond directive to do that.

But you just need to set the QSA flag to get the initial query string appended to the new one:

RewriteRule category/([^.]+)/$ /vedio/category.php?cat=$1 [QSA]
征﹌骨岁月お 2024-08-02 00:28:17

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

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

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

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文