Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Apache mod_重写以直接访问子域_Apache_Mod Rewrite - Fatal编程技术网

Apache mod_重写以直接访问子域

Apache mod_重写以直接访问子域,apache,mod-rewrite,Apache,Mod Rewrite,我们正在设置一个API,希望使用Apache mod_rewrite将所有访问指向位于/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.

我们正在设置一个API,希望使用Apache mod_rewrite将所有访问指向位于/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.

如果我们尝试正确访问脚本函数。我们做错了什么?请帮忙!提前感谢。

我假设您正在
.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]

完全正确我认为通过在.htaccess中使用L标志,它只是重定向到脚本并停止处理任何其他规则。我猜你每天都会学到新东西。再次感谢!