gpt4 book ai didi

php - .htaccess 与产品(字符串)

转载 作者:可可西里 更新时间:2023-10-31 22:12:07 25 4
gpt4 key购买 nike

我使用 .htaccess 并且我有一个允许我在我的数据库中动态查找产品的规则。

所以有人可以点击像这样的链接:

www.domain.com/product/modular-plastic-lunch-set.html

并查看产品。现在我的问题是,当我使用

www.domain.com/product/Modular-Plastic-Lunch-Set.html

它不起作用,

为什么?这是我的规则:

RewriteEngine On
RewriteRule ^product/([a-z0-9\-]+).html$ products.php?name=$1

最佳答案

它不起作用,因为您没有 A-Z[NC] 标志。

Use of the [NC] flag causes the RewriteRule to be matched in a case-insensitive manner. That is, it doesn't care whether letters appear as upper-case or lower-case in the matched URI.

RewriteRule ^product/([a-z0-9\-]+).html$ php.php?name=$1 [NC,L,QSA]

RewriteRule ^product/([a-zA-Z0-9\-]+).html$ php.php?name=$1 [L,QSA]

我加了L:

The [L] flag causes mod_rewrite to stop processing the rule set. In most contexts, this means that if the rule matches, no further rules will be processed. This corresponds to the last command in Perl, or the break command in C. Use this flag to indicate that the current rule should be applied immediately without considering further rules.

和 QSA 标志:

When the replacement URI contains a query string, the default behavior of RewriteRule is to discard the existing query string, and replace it with the newly generated one. Using the [QSA] flag causes the query strings to be combined.

有关标志的更多信息:http://httpd.apache.org/docs/2.3/rewrite/flags.html

提示:如果您使用该名称查找产品,您可能会发现查询出现延迟,尤其是在您没有索引的情况下。你应该在它变得丑陋之前调查一下。

关于php - .htaccess 与产品(字符串),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8621265/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com