我可以将这两个.htaccess文件合并为一个吗?

时间:2012-12-30 04:40:11

标签: .htaccess mod-rewrite url-rewriting apache2 rewrite

可以将这两个.htaccess文件合并为一个吗?它们处理两个独立的PHP应用程序,它们完全独立于URL处理。我想尝试一个的原因是因为mod_security抛出错误并完全忽略链中的第二个.htaccess文件,但似乎没有一个.htaccess文件的问题。

所以,如果进入/ blah,第一个应用程序处理漂亮的URL处理。但如果有人去/ members / blah,第二个应用程序会处理漂亮的URL处理。但是,请注意-f和-d参数,我们检查实际的文件或目录路径,并允许它们通过。

在根目录中:

RewriteEngine On
RewriteRule ^index\.php$ - [L]
RewriteRule ^members$ /members/ [QSA,L]
RewriteRule ^members/(.*)$ /memberapp/$1 [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

在/ memberapp:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /memberapp/index.php [QSA]

编辑1:

所以,这是映射示例:

domain.com = domain.com/index.php
domain.com/ = domain.com/index.php
domain.com/?test=test = domain.com/index.php
domain.com/members/test.png = domain.com/memberapp/test.png (file exists)
domain.com/members/dir1 = domain.com/memberapp/dir1 (directory exists)
domain.com/members/dir1/ = domain.com/memberapp/dir1 (ditto)
domain.com/test = domain.com/index.php
domain.com/members/login = domain.com/memberapp/index.php
domain.com/members/test.php = domain.com/memberapp/test.php (file exists)
domain.com/dir1 = domain.com/dir1 (directory exists)
domain.com/dir1/ = domain.com/dir1 (directory exists)
domain.com/test.png = domain.com/test.png (file exists)
domain.com/members/login?test=test = domain.com/memberapp/index.php

1 个答案:

答案 0 :(得分:1)

RewriteEngine On

RewriteRule ^index\.php$ - [L]
RewriteRule ^members$ /members/ [R=302,L]
RewriteRule ^members/(.*)$ /memberapp/$1 [QSA,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^membersapp/ /memberapp/index.php [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]