【发布时间】:2017-02-02 01:59:11
【问题描述】:
假设如下结构:
/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,它有自己的 .htaccess 文件和规则,允许其他 CMS 管理自己的网站部分。对https://example.com/main-cms/bar/another-cms/* 的请求由其他 CMS .htaccess 处理,而不会受到主要的干扰。
现在如何让主 CMS .htaccess(指向 /main-cms/index.php)处理对 https://example.com/main-cms/bar/ 和 https://example.com/main-cms/bar/baz 的请求?我得到一个带有上述代码的 404,因为bar 目录存在但/main-cms/bar/ 中没有索引页。删除!-d 条件将中断对/main-cms/foo/ 的请求。
这只能通过/main-cms/bar/ 目录中的第三个 .htaccess 手动重定向来解决,还是有一些条件/规则魔法可以在主 .htaccess 中起作用?
【问题讨论】:
标签: .htaccess mod-rewrite