首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >.htaccess不能正常工作

.htaccess不能正常工作
EN

Stack Overflow用户
提问于 2011-12-19 16:51:43
回答 3查看 294关注 0票数 1

我有.htaccess文件,其中包括以下代码。

代码语言:javascript
复制
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文件

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2011-12-19 17:53:03

尝尝这个

代码语言:javascript
复制
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
票数 1
EN

Stack Overflow用户

发布于 2011-12-19 16:58:21

你应该把最后一个规则1的位置放在上面。此规则RewriteRule ^(.*)$ index.php?q=$1 [L]将匹配任何内容,其中的L属性表示匹配时不会对其他规则求值。如果你像下面这样重新排序,它应该可以工作。

代码语言:javascript
复制
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^imagefactory/(.*)$ imagefactory/index.php?q=$1 [QSA]
RewriteRule ^(.*)$ index.php?q=$1
票数 0
EN

Stack Overflow用户

发布于 2011-12-19 17:16:42

将按顺序读取.htaccess文件。RewriteCond只适用于一条规则。

因此,您需要做的就是:

代码语言:javascript
复制
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。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8558929

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档