重定向时出现 htaccess 错误 - 重定向次数过多

发布于 2025-01-14 16:33:27 字数 1179 浏览 2 评论 0原文

我正在尝试将所有请求从一个域 (domain.co.in) 重定向到另一个域 (domain.info.in)。我已经在 htaccess 中尝试过重写指令和重定向指令,但在浏览器中出现太多重定向错误。以下是我尝试实现的配置。

RewriteEngine On

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

RewriteCond %{HTTP_HOST} ^(www\.)?domain\.co\.in [NC]
RewriteRule ^(.*)$ index.php/$1 
RewriteRule ^(.*)$ http://domain.info.in/$1 [R,L]

我实际工作的 htaccess 配置是

RewriteEngine On

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

RewriteRule ^(.+)$ index.php/$1 

使用这个,我能够将所有请求重定向到 index.php 并且工作正常。但是当我添加域重写规则时,我收到重定向错误。我也尝试过重定向指令, 重定向 302 / http://domain.info.in/index.php/$1,但同样的错误。

我尝试了本文中提到的 Fiddler 工具,调试 .htaccess 重写的提示规则。在那里它工作得很好。

实际上,我想重定向所有请求(www.domain.co.in,domain.co.in ,www.domain.info.in) 到domain.info.in

对此有什么建议吗?

I'm trying to redirect all requests from one domain (domain.co.in) to another domain (domain.info.in). I've tried Rewrite directives and Redirect directive in htaccess, but getting too many redirects error in browser. Below is the configuration I'm trying to implement.

RewriteEngine On

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

RewriteCond %{HTTP_HOST} ^(www\.)?domain\.co\.in [NC]
RewriteRule ^(.*)$ index.php/$1 
RewriteRule ^(.*)$ http://domain.info.in/$1 [R,L]

My actual working htaccess configuration is

RewriteEngine On

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

RewriteRule ^(.+)$ index.php/$1 

Using this, I'm able to redirect all requests to index.php and working fine. But when I add domain rewrite rules, I'm getting the redirect error. I've tried Redirect directive also,
Redirect 302 / http://domain.info.in/index.php/$1, but same error.

I tried the Fiddler tool mentioned in this post, Tips for debugging .htaccess rewrite rules. There it is working good.

Actually, I want to redirect all requests (www.domain.co.in, domain.co.in, www.domain.info.in) to domain.info.in

Any suggestions on this?

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

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

发布评论

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

评论(1

待"谢繁草 2025-01-21 16:33:27

根据 @CBroe 的建议,我已经更新了配置并且它可以工作。正如他所说,

RewriteConds 总是影响直接跟随的规则。

我还在检查中添加了否定,以重定向所有其他请求。

RewriteEngine On

RewriteCond %{HTTP_HOST} !^domain.co.in$ [NC]
RewriteRule ^(.*)$ http://domain.info.in/$1 [R,L]

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

RewriteRule ^(.+)$ index.php/$1 [L]

As per @CBroe's suggestion, I've updated the configuration and it works. As he said,

RewriteConds always affect the directly following rule.

And I've also added negation to the checking to redirect all other requests.

RewriteEngine On

RewriteCond %{HTTP_HOST} !^domain.co.in$ [NC]
RewriteRule ^(.*)$ http://domain.info.in/$1 [R,L]

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

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