2011-12-19 245 views
1

我有.htaccess文件,其中包括以下代码。.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文件满足以下要求。 if 1)url/admin然后转到admin文件夹并选择它的.htaccess文件 2)url/imagefactory然后进入imagefactory文件夹并选择它的文件名为index.php 3)url /然后选择根目录index.php文件

+0

你有完全控制权?如果是,请不要使用.htaccess,而应使用虚拟主机和“”声明。 – fge 2011-12-19 08:55:59

+0

只是如果用户转到url /那么它将默认索引。[PHP的,HTML等],如果你使用Apache(即时通讯不知道其他网络服务器)。 至于其他的,你可能必须做一个重定向,因为你在那里做什么意味着这两个将是有效的iirc;所以我的意思是:url/admin和url/this/is/my/admin /文件夹都是有效的。 – DarkMantis 2011-12-19 08:56:38

回答

1

尝试在Apache服务器这

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 
+0

Thanx很多Shoogle..This代码工作正常.. – meghshah 2011-12-19 09:54:26

0

您应该放置最后一个规则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 
0

按顺序读取.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] 

第二块是包罗万象的,这样,如果它不是从目录管理,使用默认的根index.php文件。

+0

它给出了这样的错误:内部服务器错误 – meghshah 2011-12-19 09:32:04