Php 使用影响其他规则的上一个规则进行mod_重写
我有下一个Php 使用影响其他规则的上一个规则进行mod_重写,php,apache,.htaccess,mod-rewrite,url-rewriting,Php,Apache,.htaccess,Mod Rewrite,Url Rewriting,我有下一个重写规则,可以访问 domain.com/section/products/whatever 从名为\u products的文件夹中。原始URL如下所示: domain.com/section/_products/product.php?param=whatever Options +FollowSymlinks -Indexes -MultiViews RewriteEngine on RewriteBase / # skip all files and directories
重写规则
,可以访问
domain.com/section/products/whatever
从名为\u products
的文件夹中。原始URL如下所示:
domain.com/section/_products/product.php?param=whatever
Options +FollowSymlinks -Indexes -MultiViews
RewriteEngine on
RewriteBase /
# skip all files and directories from rewrite rules below
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]
RewriteRule ^(section/products/brand)/([^/]+)$ $1/index.php?brand=$2 [QSA,L,NC]
RewriteRule ^(section)/products/(.*)$ $1/_products/$1 [L,NC,QSA]
这是一条规则:
RewriteRule ^section/products/(.*)$ section/_products/$1 [L,NC]
现在我需要重写此URL:
domain.com/section/products/brand/index.php?brand=apple
对于这一点:
domain.com/section/products/brand/apple
我正在尝试这样做:
Options -Indexes
Options +FollowSymlinks
Options -MultiViews
RewriteEngine on
RewriteBase /
RewriteRule ^section/products/(.*)$ section/_products/$1 [L,NC]
RewriteRule ^(section/products/brand)/([\w-]+)$ /section/_products/brand/index.php?brand=$1 [QSA,L,NC]
RewriteRule ^(section/products/brand)/([\w-]+)$ /section/products/brand/index.php?brand=$1 [QSA,L,NC]
还有:
Options -Indexes
Options +FollowSymlinks
Options -MultiViews
RewriteEngine on
RewriteBase /
RewriteRule ^section/products/(.*)$ section/_products/$1 [L,NC]
RewriteRule ^(section/products/brand)/([\w-]+)$ /section/_products/brand/index.php?brand=$1 [QSA,L,NC]
RewriteRule ^(section/products/brand)/([\w-]+)$ /section/products/brand/index.php?brand=$1 [QSA,L,NC]
这两个人都不为我工作
部分/_products/$1
规则应该在另一条规则之后还是之前?
我找不到正确的逻辑。你可以这样做:
domain.com/section/_products/product.php?param=whatever
Options +FollowSymlinks -Indexes -MultiViews
RewriteEngine on
RewriteBase /
# skip all files and directories from rewrite rules below
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]
RewriteRule ^(section/products/brand)/([^/]+)$ $1/index.php?brand=$2 [QSA,L,NC]
RewriteRule ^(section)/products/(.*)$ $1/_products/$1 [L,NC,QSA]
第一条规则对我有效,但替换第二条规则会导致服务器抛出500个错误。谢谢但看起来它不接受空格?我有一些带有空格的
?brand=
(URL中不使用“%20”)。我用这个正则表达式解决了这个问题:([\w-\s]+)$
谢谢!