【问题标题】:CURL on localhost with MOD_REWRITE -> 404 (but fine in browser)使用 MOD_REWRITE -> 404 在 localhost 上的 CURL(但在浏览器中很好)
【发布时间】:2012-04-21 15:39:55
【问题描述】:

我的本​​地服务器 (http://localhost/) 上托管了一个网站,该网站使用 url_rewriting。

当我使用浏览器访问页面时,没问题,它正在加载。
但是当我使用 PHP cUrl 访问相同的 url 时,我得到了 404。

示例:
带有 mod_rewrite 的 URL:http://localhost/site/test
实页:http://localhost/site/test.php

从 Firefox 加载 http://localhost/site/test:工作中

使用 cUrl 加载:

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://localhost/site/test");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$output = curl_exec($ch);
curl_close($ch);

$output -> 来自 apache 的 404 页面

有人知道为什么 cUrl 返回 404 消息吗?

【问题讨论】:

  • 找出您的网络服务器为 cURL 请求返​​回 404 的原因。也许请求不是您认为的那样,也许您的网络服务器打开了一些可选的标头(如 User-Agent)。添加一个RewriteRule,就像一个包罗万象,记录请求并进行比较。
  • 你的 RewriteRules 是什么?你是在做外部重定向还是内部重写?如果是前者,您需要在 curl 配置中包含以下选项。

标签: php mod-rewrite curl url-rewriting localhost


【解决方案1】:

原来这与 mod_rewrite 无关。
URL 中的一个目录中有一个空格,我在调用 cUrl 函数时没有对其进行编码。 将所有空间替换为 %20 后,一切正常。

主题已关闭。

【讨论】:

    猜你喜欢
    • 2023-03-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-03-17
    • 2017-06-10
    • 1970-01-01
    • 2016-05-16
    • 1970-01-01
    相关资源
    最近更新 更多