【发布时间】: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