我需要两个条件规则。背景:
http://www.domain.com/.htaccess http://www.domain.com/index.php http://www.domain.com/admin/index.php
我有两个重写规则:
ROOT: RewriteEngine On RewriteCond %{QUERY_STRING} ^(.*)$ RewriteRule ^(.*/)([^/]+)/([^/]+) $1?$2=$3&%1 [L] RewriteCond %{QUERY_STRING} ^(.*)$ RewriteRule ^([^/]+)/ $1.php?%1 [L] ADMIN: RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^([a-z]+?)/([a-z]+?)/(.*)$ index.php?model=$1&view=$2¶ms=$3 [L,NS]
我需要以某种方式只在根级别上只有一个.htaccess文件使用这两个规则,但ADMIN规则仅在url http://www.domain.com/admin/foo/bar/something/else
和ROOT规则适用于http://www.domain.com/foo/bar/something/else
时适用。
先谢谢你,我已经杀了一整天试图这样做,当一个人工作时,另一个人给我一个“未找到”页面错误。
克里斯
答案 0 :(得分:2)
RewriteCond %{REQUEST_URI} !^/admin/
RewriteCond %{QUERY_STRING} (.*)
RewriteRule ^(.*/)([^/]+)/([^/]+) $1?$2=$3&%1 [L]
RewriteCond %{REQUEST_URI} !^/admin/
RewriteCond %{QUERY_STRING} (.*)
RewriteRule ^([^/]+)/ $1.php?%1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^admin/([a-z]+?)/([a-z]+?)/(.*)$ /admin/index.php?model=$1&view=$2¶ms=$3 [L,NS]
答案 1 :(得分:1)
我会用这个:
RewriteEngine On
# /admin/ rule
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^admin/([a-z]+)/([a-z]+)/(.*)$ admin/index.php?model=$1&view=$2¶ms=$3 [L,NS]
RewriteRule ^admin/ - [L]
# other rules
RewriteRule ^(.*/)([^/]+)/([^/]+)$ $1?$2=$3 [L,QSA]
RewriteRule ^([^/]+)/ $1.php [L,QSA]
QSA
标志(查询字符串追加)替换RewriteCond %{QUERY_STRING} (.*)
指令。