我有.htaccess文件,其中包括以下代码。
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L]
RewriteRule ^imagefactory/(.*)$ imagefactory/index.php?q=$1 [QSA]我想要满足以下要求的.htaccess文件。如果1) index.php / admin,则转到管理文件夹并选择它的.htaccess文件2) url/imagefactory然后转到imagefactory文件夹并选择它的名为index.php的文件3) url/然后它选择根目录的index.php文件
发布于 2011-12-19 17:53:03
尝尝这个
RewriteEngine on
RewriteRule ^imagefactory/(.*)$ imagefactory/index.php?q=$1 [QSA]
RewriteRule ^admin/.$ - [PT]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1发布于 2011-12-19 16:58:21
你应该把最后一个规则1的位置放在上面。此规则RewriteRule ^(.*)$ index.php?q=$1 [L]将匹配任何内容,其中的L属性表示匹配时不会对其他规则求值。如果你像下面这样重新排序,它应该可以工作。
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^imagefactory/(.*)$ imagefactory/index.php?q=$1 [QSA]
RewriteRule ^(.*)$ index.php?q=$1发布于 2011-12-19 17:16:42
将按顺序读取.htaccess文件。RewriteCond只适用于一条规则。
因此,您需要做的就是:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^imagefactory/(.*)$ imagefactory/index.php?q=$1 [QSA, L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/admin/(.*)$
RewriteRule ^(.*)$ index.php?q=$1 [QSA, L]第二个块是catch all,因此如果它不是来自目录管理,则使用默认的根index.php。
https://stackoverflow.com/questions/8558929
复制相似问题