Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.htaccess 嵌套目录中多个CMSE的htaccess_.htaccess_Mod Rewrite - Fatal编程技术网

.htaccess 嵌套目录中多个CMSE的htaccess

.htaccess 嵌套目录中多个CMSE的htaccess,.htaccess,mod-rewrite,.htaccess,Mod Rewrite,假设以下结构: /main-cms/index.php /main-cms/a-thing.php /main-cms/foo/index.php /main-cms/bar/another-cms/index.php /main-cms/bar/another-cms/another-thing.php 我想要一个不存在的URL,如https://example.com/main-cms/hello由主CMS的index.php文件和正常服务的实际文件处理,如https://example.

假设以下结构:

/main-cms/index.php
/main-cms/a-thing.php
/main-cms/foo/index.php
/main-cms/bar/another-cms/index.php
/main-cms/bar/another-cms/another-thing.php
我想要一个不存在的URL,如
https://example.com/main-cms/hello
由主CMS的index.php文件和正常服务的实际文件处理,如
https://example.com/main-cms/a-thing.php
https://example.com/main-cms/foo/

以下.htaccess可以很好地实现这一点:

RewriteBase /main-cms/
RewriteCond %{REQUEST_FILENAME} !-f [OR]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
我还有另一个CMS在主CMS的子目录中,它有自己的.htaccess文件和规则,允许其他CMS管理自己的站点部分。请求
https://example.com/main-cms/bar/another-cms/*
由另一个CMS.htaccess处理,而不受主CMS.htaccess的干扰

现在我如何获取对
https://example.com/main-cms/bar/
https://example.com/main-cms/bar/baz
是否由主CMS.htaccess(指向
/main CMS/index.php
)处理?我用上面的代码得到一个404,因为
bar
目录存在,但
/main cms/bar/
中没有索引页。删除
-d
条件将中断对
/main cms/foo/
的请求


这只能通过
/main cms/bar/
目录中的第三个.htaccess手动重定向来解决,还是有一些条件/规则魔法可以在main.htaccess中工作?

听起来您根本不需要
bar
目录。将嵌套的CMS向上移动一级。您需要忽略对主CMS中嵌套CMS的请求,因此请首先执行以下规则:

RewriteCond ^another-cms/ - [L]
在嵌套的一个中,设置

RewriteBase /main-cms/another-cms/

网络根目录中有什么?那就是我希望你的主要CMS所在的地方。如果它是空的,比如
,对它做同样的事情。

我的例子是将一个带有多个自助服务应用程序(不同的非传统CMS)的大型网站迁移到一个新的web CMS,以处理驻留在其他CMS中的大多数传统静态内容。移动目录将打破20多年来建立的链接。虽然这当然是可行的,但我更愿意在没有大量重定向的情况下维护现有结构。