【问题标题】:"http://" in query string does not work查询字符串中的“http://”不起作用
【发布时间】:2012-06-15 01:45:25
【问题描述】:

更新:

我在子域中进行了测试 - 没有 .htaccess 和 PHP。 我创建了一个index.html 并尝试访问/?p=http://?p=http://。 我收到/?p=http:// 的此错误

Forbidden

You don't have permission to access / on this server.

Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.

Apache Server at test.example.com Port 80

这排除了任何 PHP 或 mod_rewrite 问题。 Apache 出了什么问题?

案例 1(不起作用): mysite.com?p=http://

案例 2(工作): mysite.com?p=http://

如果查询字符串中有http://https://ftp://,即使我对其进行了编码,也会出现错误。 我有一个index.php(入口脚本)和一个test.php(用于测试这个错误)。如果我在查询字符串中访问带有http:// 的URL(通过index.php),即使有其他参数,$_GET 变量也会为空。如果我访问test.php?p=http://,我会被重定向(URL 没有变化)到index.php 并出现错误(框架处理无效请求)。用其他东西替换 http:// 后,一切正常 - test.php 显示了它的含义,所有其他请求都转到 index.php 并填充了 $_GET

我只是在移动到新主机(hostdime 到 hostgator)后才注意到这个错误。我无法在其他任何地方(旧主机、本地服务器)重现此内容。

谢谢。

我的 .htaccess 文件,去掉了一些不相关的代码。

# Use PHP 5.3
AddType application/x-httpd-php53 .php

# ----------------------------------------------------------------------
# Start rewrite engine
# ----------------------------------------------------------------------

<IfModule mod_rewrite.c>
    Options +FollowSymlinks
    RewriteEngine On

    # removes www.
    # ------------------------------------------------------------------
    RewriteCond %{HTTPS} !=on
    RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
    RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L]

    # rewrite "domain.com/foo -> domain.com/foo/"
    # ------------------------------------------------------------------
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/|#(.*))$
    RewriteRule ^(.*)$ /$1/ [R=301,L]

    # Yii specific rewrite
    # ------------------------------------------------------------------
    # if a directory or a file exists, use it directly
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    # otherwise forward it to index.php
    RewriteRule . index.php 
</IfModule>


# without -MultiViews, Apache will give a 404 for a rewrite if a folder of the same name does not exist 
# ------------------------------------------------------------------
Options -MultiViews 



# ----------------------------------------------------------------------
# UTF-8 encoding
# ----------------------------------------------------------------------

# Use UTF-8 encoding for anything served text/plain or text/html
AddDefaultCharset utf-8

# Force UTF-8 for a number of file formats
AddCharset utf-8 .html .css .js .xml .json .rss .atom


# ----------------------------------------------------------------------
# Gzip compression
# ----------------------------------------------------------------------

<IfModule mod_deflate.c>
...
</IfModule>


<IfModule mod_expires.c>
...
</IfModule>


<IfModule mod_autoindex.c>
    Options -Indexes
</IfModule>


# Block access to "hidden" directories whose names begin with a period. This
# includes directories used by version control systems such as Subversion or Git.
<IfModule mod_rewrite.c>
    RewriteCond %{SCRIPT_FILENAME} -d
    RewriteCond %{SCRIPT_FILENAME} -f
    RewriteRule "(^|/)\." - [F]
</IfModule>

# Increase cookie security
<IfModule php5_module>
    php_value session.cookie_httponly true
</IfModule>

【问题讨论】:

  • 我总是对查询中使用的任何参数进行urlencode。简单地说,这是最佳做法。
  • 我总是对它们进行编码。我只是举个例子。
  • 您可以尝试的是,使用所用协议的值设置第二个 GET 变量,例如:mysite.com/?p=tosomesite.com&pro=http 并在代码中将该协议添加到域... $final_link = $_GET['pro'].'://'.$_GET['p'];

标签: php .htaccess mod-rewrite


【解决方案1】:

所以显然这是主机的问题。我联系了 HostGator 寻求帮助,他们说这是一个 mod_security 问题。 如果您在尝试解释时遇到困难,请告诉他们在您提供的链接上运行 apachetail 命令。

这些链接可能会对您有所帮助

http://forums.hostgator.com/mod-security-and-403-errors-t71394.html

http://www.codingforums.com/showthread.php?t=233958

http://www.codingforums.com/showthread.php?t=244525

【讨论】:

  • 这个问题真让我抓狂,每次你想创建一个带有http的帖子,你必须去Hostgator支持并要求每次将url添加到白名单,这很无聊.
【解决方案2】:

我对 HostGator 也有类似的问题。您可以通过实时聊天询问他们的技术支持,将您想要将 url 放入查询字符串中的域名列入白名单。 Dalton Tan 提供的资源很好读,尤其是 HG 论坛的第一个。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-11
    相关资源
    最近更新 更多