【问题标题】:mod_rewrite To Direct Subdomain Accessmod_rewrite 直接访问子域
【发布时间】:2010-09-04 05:33:26
【问题描述】:

我们正在设置一个 API,我们希望使用 Apache mod_rewrite 将所有对 http://api.domain.com 的访问定向到位于 /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,脚本会正常运行。我们做错了什么?请帮忙!提前致谢。

【问题讨论】:

    标签: apache mod-rewrite


    【解决方案1】:

    我假设您在.htaccess 文件中定义规则,其中L 标志might not work like you were expecting

    由于您的测试模式 ^(.*)$ 匹配给它的任何输入,因此您重写的 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]
    

    【讨论】:

    • 正确。我认为通过在 .htaccess 中使用 L 标志,它只是重定向到脚本并停止处理任何其他规则。我猜你每天都会学到一些新东西。再次感谢!
    猜你喜欢
    • 1970-01-01
    • 2015-10-07
    • 2011-08-11
    • 1970-01-01
    • 2011-07-21
    • 2013-04-04
    • 1970-01-01
    • 2019-05-26
    • 2013-08-04
    相关资源
    最近更新 更多