Apache .htaccess 和 Zend Rewrite 与重定向冲突

发布于 2025-01-08 04:24:01 字数 585 浏览 4 评论 0原文

我正在使用此 .htaccess 代码将旧域重定向到新域:

Options +FollowSymLinks
RewriteEngine on

RewriteCond %{HTTP_HOST} test.domain.eu(.*)
RewriteRule (.*) http://test.domain.be/$1 [R=301,L]

这也适用于子目录。但在目录 /project 中,有一个带有以下 .htaccess 的 Zend 项目:

SetEnv APPLICATION_ENV development

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

当我转到旧域上的该目录时,重定向不起作用。所以我猜测这两个 .htaccess 文件彼此冲突。有谁知道如何进行这项工作?

I'm using this .htaccess code to redirect the old domain to the new domain:

Options +FollowSymLinks
RewriteEngine on

RewriteCond %{HTTP_HOST} test.domain.eu(.*)
RewriteRule (.*) http://test.domain.be/$1 [R=301,L]

This works, also for subdirectories. But in the directory /project, there's a Zend project with the following .htaccess:

SetEnv APPLICATION_ENV development

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

When I go that directory on the old domain, the redirect doesn't work. So I'm guessing these 2 .htaccess files conflict eachother. Does anyone have an idea how to make this work?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

迟到的我 2025-01-15 04:24:01

将以下 2 条规则添加

RewriteCond %{HTTP_HOST} test.domain.eu(.*)
RewriteRule (.*) http://test.domain.be/$1 [R=301,L]

/project 的 .htaccess 中。

当发出 URI 请求时,会在最底层目录中查找带有 .htaccess 的 .htaccess & 。使用过。

礼貌:@TerryE

  • /folder/folder1/folder2 是请求的 URI,假设它们都有 .htaccess 那么,folder2 的 .htaccess只会被使用。

  • /folder/folder1/folder2 是请求的 URI,假设只有 folder1.htaccess,那么,folder1 的 .htaccess 只会被使用。


所以,这样做:

SetEnv APPLICATION_ENV development

RewriteEngine On

RewriteCond %{HTTP_HOST} test.domain.eu
RewriteRule (.*) http://test.domain.be/project/$1 [R=301,L]

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

Add these 2 rules:

RewriteCond %{HTTP_HOST} test.domain.eu(.*)
RewriteRule (.*) http://test.domain.be/$1 [R=301,L]

to /project's .htaccess as well.

When an URI request is made, the .htaccess in the lower most directory with .htaccess is looked for & used.

Courtesy: @TerryE.

i.e.

  • /folder/folder1/folder2 is the requested URI, and lets say all of them has .htaccess then, folder2's .htaccess will only be used.

  • /folder/folder1/folder2 is the requested URI, and lets say only folder1 has a .htaccess then, folder1's .htaccess will only be used.


So, do this:

SetEnv APPLICATION_ENV development

RewriteEngine On

RewriteCond %{HTTP_HOST} test.domain.eu
RewriteRule (.*) http://test.domain.be/project/$1 [R=301,L]

RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文