Mod_重写问题

发布于 2024-10-08 04:16:08 字数 246 浏览 0 评论 0原文

如何使用 mod_rewrite 将以下 URL 示例 1 转换为示例 2?

实施例1

http://www.example.com/cat/index.php?cat=fruit&sub1=apple&sub2=green

实施例2

http://www.example.com/cat/fruit/apple/green/

How can I turn the following URL example 1 to example 2 using mod_rewrite?

Example 1

http://www.example.com/cat/index.php?cat=fruit&sub1=apple&sub2=green

Example 2

http://www.example.com/cat/fruit/apple/green/

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

眼泪淡了忧伤 2024-10-15 04:16:08

使用类似这样的内容:

RewriteRule ^(.*)/(.*)/(.*)/(.*)/$ index.php?$1=$2&sub1=$3&sub2=$4 [NC]

$1$2$3$4 代表四个匹配组 (. *)

如果子类别的数量可变,您应该更改策略:

RewriteRule ^(.*)/(.*)/(.*)/$ index.php?$1=$2&subcat_string=$3 [NC]

并手动解析 subcat_string(Python 中的示例):

# subcat_string will be something like "apple/green"
subcats = subcat_string.split("/")
# subcats is now ["apple", "green"]

Use something like this:

RewriteRule ^(.*)/(.*)/(.*)/(.*)/$ index.php?$1=$2&sub1=$3&sub2=$4 [NC]

$1, $2, $3 and $4 represent the four matched groups (.*)

If there is a variable number of subcategories, you should change your strategy:

RewriteRule ^(.*)/(.*)/(.*)/$ index.php?$1=$2&subcat_string=$3 [NC]

And parse the subcat_string manually (example in python):

# subcat_string will be something like "apple/green"
subcats = subcat_string.split("/")
# subcats is now ["apple", "green"]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文