mod_rewrite 直接子域访问

发布于 2024-09-18 08:55:20 字数 989 浏览 3 评论 0原文

我们正在设置一个 API,我们希望使用 Apache mod_rewrite 将所有访问定向到 http://api.domain.com< /a> 到位于 /cgi-bin/api.pl 的脚本。这是我们当前正在使用的:

RewriteEngine on

RewriteCond %{HTTP_HOST} ^api.domain.com$ [NC]
RewriteRule ^(.*)$ /cgi-bin/api.pl [NC,L,QSA]

但是,这给我们带来了以下错误:

[Fri Sep 03 14:18:32 2010] [error] [client 67.180.34.0] mod_rewrite: maximum number of internal redirects reached. Assuming configuration error. Use 'RewriteOptions MaxRedirects' to increase the limit if neccessary.
[Fri Sep 03 14:18:32 2010] [error] [client 67.180.34.0] Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace.

如果我们尝试访问 http://domain.com/cgi-bin/api.pl 脚本正常运行。我们做错了什么?请帮忙!提前致谢。

We are setting up an API and we want to use Apache mod_rewrite to direct all accesses to http://api.domain.com to the script located at /cgi-bin/api.pl. Here is what we're currently using:

RewriteEngine on

RewriteCond %{HTTP_HOST} ^api.domain.com$ [NC]
RewriteRule ^(.*)$ /cgi-bin/api.pl [NC,L,QSA]

However, this is giving us the following error:

[Fri Sep 03 14:18:32 2010] [error] [client 67.180.34.0] mod_rewrite: maximum number of internal redirects reached. Assuming configuration error. Use 'RewriteOptions MaxRedirects' to increase the limit if neccessary.
[Fri Sep 03 14:18:32 2010] [error] [client 67.180.34.0] Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace.

If we try to access http://domain.com/cgi-bin/api.pl the script functions properly. What are we doing wrong? Please help! Thanks in advance.

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

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

发布评论

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

评论(1

梦开始←不甜 2024-09-25 08:55:20

我假设您在 .htaccess 文件中定义规则,其中 L 标志 可能不会像您预期的那样工作

由于您的测试模式 ^(.*)$ 与提供给它的任何输入相匹配,因此您重写的 URL 也会在后续请求中匹配,并且您会得到一个内部无限重定向循环(最终导致服务器错误)。

解决方案是检查您是否已经重写了 URL:

RewriteEngine on

RewriteCond %{REQUEST_URI} !=/cgi-bin/api.pl
RewriteCond %{HTTP_HOST} ^api.domain.com$ [NC]
RewriteRule ^.*$ /cgi-bin/api.pl [NC,L,QSA]

I assume that you're defining your rules in a .htaccess file, where the L flag might not work like you were expecting.

Since your test pattern ^(.*)$ matches whatever input is given to it, the URL you rewrite to is also matched on the subsequent request, and you get an internal infinite redirection loop (resulting eventually in the server error).

A solution is to check to see if you've already rewritten the URL:

RewriteEngine on

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