将两个项目中的两个.htaccess文件合并为一个 [英] Merge two .htaccess files from two projects into one

查看:133
本文介绍了将两个项目中的两个.htaccess文件合并为一个的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个项目,我必须将其包含在项目中. 因此,..项目A是一个基于自定义框架构建的网站,该框架使用以下.htaccess重写规则:

I have a project which I have to include within a project. So .. project A is a web site built on top of custom framework which uses this .htaccess rewrite rules:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^(.*)$ index.php?url=$1 [PT,L]

第二个项目B建立在另一个自定义框架之上,我应该使它看起来像第一个项目的子文件夹. 因此,我将项目B放在文件夹子文件夹"中.项目B具有自己的.htaccess,如下所示:

The second project B is built on top of another custom framework and I am supposed to make it look like a subfolder to the first one. So I placed project B inside a folder "subfolder". Project B has its own .htaccess which looks like this:

RewriteCond%{REQUEST_FILENAME}!-f

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond%{REQUEST_FILENAME}!-d

RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^(.*)$ index.php?request =%{REQUEST_URI}&%{QUERY_STRING} [NE,L]

RewriteRule ^(.*)$ index.php?request=%{REQUEST_URI}&%{QUERY_STRING} [NE,L]

我想将它们合并到一个.htacess文件中,并告诉Apache类似的东西:

I want to merge them into a single .htacess file and tell to Apache something like :

如果我们有一个参数/subfolder,则将所有内容重定向到subfolder/index.php

if we have a parameter /subfolder redirect everything to subfolder/index.php

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

else redirect everything to index.php

任何想法我该怎么做?

推荐答案

您应该做的是:

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

For the first project, this htaccess file is in the document root

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

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

Then in the second project, this htaccess file is in the subfolder directory:

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

如果由于某种原因对您不起作用,我猜一个合并的htaccess文件(位于文档根目录中)看起来像这样:

If for some reason that's not working for you, I guess a combined htaccess file, one that resides in the document root, would look like this:

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]

可能需要更多调整.

这篇关于将两个项目中的两个.htaccess文件合并为一个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆