具有多个重写规则的 Htaccess

问题描述

我在 htaccess 文件中的重写规则有问题。这是我的代码:

#BLOCK 1#
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^([^/]+)/$ path_to_website/file.php?product=$1&country=0&pag=pag-1&rew=1 [L]
RewriteCond %{QUERY_STRING} ^(.*)=(.*)&country=0&pag=pag-1$
RewriteCond %{QUERY_STRING} !^.*rew=1.*$
RewriteRule ^.*$ /path_to_website/%2/? [R=301,L]

#BLOCK 2#
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^([^/]+)/([^/]+)/$ path_to_website/file.php?product=$1&country=$2&pag=pag-1&rew=1 [L]
RewriteCond %{QUERY_STRING} ^(.*)=(.*)&(.*)=(.*)&pag=pag-1$
RewriteCond %{QUERY_STRING} !^.*rew=1.*$
RewriteRule ^.*$ /path_to_website/%2/%4/? [R=301,L]

#BLOCK 3#
RewriteRule ^([\w-]+)/?$ path_to_website/file.php?product=$1&country=0&pag=pag-1 [L]
RewriteRule ^([\w-]+)/([\w-]+)(?!=/)$ path_to_website/file.php?product=$1&country=0&pag=$2 [L]
RewriteRule ^([\w-]+)/([\w-]+)/$ path_to_website/file.php?product=$1&country=$2&pag=pag-1 [L]
RewriteRule ^([\w-]+)/([\w-]+)/([\w-]+)$ path_to_website/file.php?product=$1&country=$2&pag=$3 [L]

前两个块来自提交表单,第三个块来自 href。

我想在不与其他规则冲突的情况下添加以下规则:

RewriteRule ^([\w-]+)/([\w-]+)/([\w-]+)$ path_to_website/file2.php?product=$1&country=$2&product-details=$3 [L]

编辑

解决了问题,我只是在重写的详细信息页面中添加了另一个参数:

RewriteRule ^([\w-]+)/([\w-]+)/([\w-]+).([\w-]+)$ path_to_website/file2.php?product=$1&country=$2&product-details=$3&place-holder=$4 [L]

解决方法

问题解决了,我只是在rewrite for details-page中添加了另一个参数:

RewriteRule ^([\w-]+)/([\w-]+)/([\w-]+).([\w-]+)$ path_to_website/file2.php?product=$1&country=$2&product-details=$3&place-holder=$4 [L]

谢谢大家:)

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...