将两个项目中的两个.htaccess文件合并为一个文件


Merge two .htaccess files from two projects into one

我有一个项目,必须包含在项目中。所以项目A是一个建立在自定义框架之上的网站,该框架使用这个。htaccess重写规则:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?url=$1 [PT,L]

第二个项目B是建立在另一个自定义框架之上的,我应该让它看起来像第一个的子文件夹。所以我把项目B放在一个文件夹";子文件夹";。项目B有自己的.htaccess,看起来像这样:

重写结束%{REQUEST_FILENAME}-f

重写结束%{REQUEST_FILENAME}-d

重写规则^(.*)$index.php?请求=%{request_URI}&%{QUERY_STRING}[NE,L]

我想将它们合并到一个.htaccess文件中,并告诉Apache类似的内容:

如果我们有一个参数/子文件夹重定向到子文件夹/index.php

else将所有内容重定向到index.php

你知道我该怎么做吗?

您应该做的是:

对于第一个项目,这个htaccess文件位于文档根中

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?url=$1 [L]

然后在第二个项目中,这个htaccess文件位于subfolder目录中:

RewriteEngine On
RewriteBase /subfolder/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?request=%{REQUEST_URI} [NE,L,QSA]

如果由于某种原因,这对您不起作用,我想一个组合的htaccess文件,一个驻留在文档根目录中的文件,看起来会是这样的:

RewriteEngine On
# for 2nd project
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/?subfolder/(.*)$ /subfolder/index.php?request=$1 [NE,L,QSA]
# for 1st project
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?url=$1 [L]

可能需要更多的调整。