htaccess获取包含特定单词的url



我有一个网站的URL像/product-category/clothing/accessories/?filter_color=yellow,现在我想将这些类型的URL重写为/index.php/product-category/clothing/accessories/?filter_color=yellow。事实上,我想在我的htaccess中添加一个重写规则,即如果URL包含product-category而不包含index.php,则重写URL开头的index.php。为此,我开发了以下代码:

<IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteCond %{REQUEST_URI} product-category RewriteRule . /index.php [L] </IfModule>

但它不能正常工作。首先,它将index.php添加到所有URL,然后在URL 中已经存在/index.php时添加额外的/

以下是完整的.htaccess文件:

htaccess

您可以使用以下规则:

RewriteRule ^product-category/.* /index.php/$0 [L,NC]

最新更新