[英]Replace string with htaccess RewriteRule
I'm trying to replace a string in URL with htaccess RewriteRule. 我正在尝试用htaccess RewriteRule替换URL中的字符串。 The idea is to catch every request beginning with
prodotti
, replace it with products
and leave the rest the same. 这个想法是要捕获每个以
prodotti
开头的请求,将其替换为products
,其余的保持不变。 For example 例如
prodotti/category/id.html
becomes products/category/id.html
prodotti/category/id.html
变为products/category/id.html
prodotti/category.html
becomes products/category.html
prodotti/category.html
变为products/category.html
prodotti.html
becomes products.html
prodotti.html
变成products.html
I've tried the following rule 我尝试了以下规则
RewriteRule ^prodotti products [QSA,NC]
(I'm omitting the L
flag because after this replacement I need to make further RewriteRules). (我省略了
L
标志,因为在此替换之后,我需要进行进一步的RewriteRules)。
The rule works fine for everything but the replacement #3 (it doesn't match). 该规则适用于除替换#3之外的所有内容(不匹配)。 How can I change it to match all replacements with a single
RewriteRule
line? 如何更改它,以使用单个
RewriteRule
行匹配所有替换项?
EDIT 编辑
Here's the list of further RewriteRules I need to perform after the replacement. 这是替换后我需要执行的其他RewriteRules的列表。
# products/category/id.html
RewriteRule ^products/([^/]+)/([^/]+)\.html$ mvc.php?rt=products/index&category=$1&id=$2 [L,QSA,NC]
# products/category.html
RewriteRule ^products/([^/]+)\.html$ mvc.php?rt=products/index&category=$1 [L,QSA,NC]
RewriteRule ^prodotti(.*)$ products$1 [QSA,NC]
尝试这个
RewriteRule ^prodotti\.html$ /products.html [QSA,NC,L]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.