使用 .htaccess 绕过 Zend 框架并在子目录中运行不同的框架



我正在尝试在Zend站点的子目录中运行一个非Zend php应用程序。我想绕过 Zend 应用程序来处理 .htaccess 中子目录"/branches"中的所有文件。到目前为止,我找到的解决方案都没有奏效。这是当前的 .htaccess 文件:

RewriteEngine on
RewriteBase /
# WWW Resolve
RewriteCond %{HTTP_HOST} ^domain.com$ [NC]
RewriteRule ^web/content/(.*)$ http://www.domain.com/$1 [R=301,L]
# Eliminate Trailing Slash
RewriteRule web/content/(.+)/$ http://www.domain.com/$1 [R=301,L]
# Route Requests
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]

这甚至可以在.htaccess中完成吗?

您目前有:

RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]

这是没有意义的,因为您指定基本上不对实际文件,目录和符号链接执行任何操作的RewriteCons将永远不起作用。这是因为,RewriteRule 紧随其后的是重写所有内容以索引.php的规则。

如果你的目的是将所有不是请求的内容定向到要索引.php文件的真实目录,你应该有这样的东西:

RewriteCond %{REQUEST_FILENAME} -s
RewriteCond %{REQUEST_FILENAME} -l
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ index.php [NC,L]

要添加忽略/branches的特殊情况,只需添加一个这样的条件:

RewriteCond %{REQUEST_FILENAME} -s
RewriteCond %{REQUEST_FILENAME} -l
RewriteCond %{REQUEST_FILENAME} -d
RewriteCond %{REQUEST_FILENAME} !^branches/
RewriteRule ^.*$ index.php [NC,L]

我能够在不更改 .htaccess 的情况下解决这个问题,而只是将我的子目录放在"/content"中。

最新更新