【问题标题】:Interpreting Apache Access Log, Site with Forced HTTPS解释 Apache 访问日志,使用强制 HTTPS 的站点
【发布时间】:2016-07-04 14:31:05
【问题描述】:

在站点 example.com 上,我在 .htaccess 中强制使用 https

RewriteEngine On 
RewriteCond %{SERVER_PORT} 80 
RewriteRule ^(.*)$ https://example.com/$1 [R,L]

供应商应该将数据发布到 https://www.example.com/membership/foobar.php,并且他们坚持使用 https 方案发布信息。

在日志中查找他们的 IP 总是遵循这种模式:

[17/Mar/2016:00:15:11 -0400] "POST /membership/foobar.php HTTP/1.1" 302 1165 731 "-" "-"   
[17/Mar/2016:00:15:11 -0400] "GET /membership/foobar.php HTTP/1.1" 200 743 2623 "-" "-"    

[17/Mar/2016:17:37:58 -0400] "POST /membership/foobar.php HTTP/1.1" 302 1179 731 "-" "-"
[17/Mar/2016:17:37:58 -0400] "GET /membership/foobar.php HTTP/1.1" 200 743 2623 "-" "-"

当我读到这篇文章时,它是一个接收 302 然后被解释为 GET 的 POST,我认为这是由于 htaccess 重写了对 http 方案的请求,而不是 https。

这是正确的解释吗?

【问题讨论】:

  • 我想是的,是的。他们通过 POST http:// 页面请求并被重定向,GET 可能是因为您的 .htaccess,或者如果在您的 PHP 代码中执行了类似 header() 的操作。在您的 .htaccess 中尝试 [R=301,L] , 表示这是一个永久重定向。

标签: apache .htaccess logging


【解决方案1】:

除非您有其他未在此处显示的规则或代码,否则 POST 请求将登陆端口 80 并以 302 状态重定向。请记住,任何 302/301 在重定向后都会变成 GET 请求,会导致过程中丢失 POST 数据。

Once 应该使用如下条件跳过这些重定向的 POST 请求:

RewriteCond %{REQUEST_METHOD} !POST
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=302,NE,L]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-01-12
    • 2012-08-09
    • 2012-03-03
    • 2015-11-27
    • 2018-01-14
    • 2017-08-11
    • 2015-01-08
    • 1970-01-01
    相关资源
    最近更新 更多