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

标签 php string .htaccess mod-rewrite

我使用 .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/

相关文章:

php - Bing Ads API PHP 报告请求无需下载

php - 如何在firebug中调试ajax响应

java - 如何阻止我的 do while 循环接受除 "stop"之外的每个字符串

php - 将 Bootstrap 集成到 codeigniter

php - 使用 htaccess 将 js/css 解析为 PHP 文件

.htaccess - 在执行第一个规则后运行第二个重写条件和规则

php - 如何使用 cURL 在 PHP 中发出 PATCH 请求?

javascript - 如何使用 Javascript 从 CSS 选择器字符串中删除所有伪选择器?

c# - .NET 中字符串的简单混淆?

php - 一些 php mysql 错误