在Querystring中使用“http://”的Mod_rewrite

时间:2009-11-08 19:47:58

标签: apache mod-rewrite

我正在尝试创建一个重写规则来执行以下操作:

http://www.example.com/http://other.example.comhttp://www.example.com/index.php?var=http://google.com

这是我目前的规则:

RewriteCond %{REQUEST_URI} ^/(http[s]?\:\/\/|ftp\:\/\/)?(www\.)?[a-zA-Z0-9-\.]+\.(com|org|net|mil|edu|ca|co.uk|com.au|gov|ws|info)$
RewriteRule ^(.*)$ http://www.example.com/index.php?var=$1 [R]

产生:

http://www.example.com/http://google.comhttp://www.example.com/index.php?var= http:/google.com

无论我尝试什么,我总是将 http:/ 取出,而不是 http:// 。有什么想法吗?

1 个答案:

答案 0 :(得分:0)

Apache删除http://中的空路径段。因此/foo//bar///被解释为/foo/bar/。但THE_REQUEST中的原始请求行保持不变:

RewriteCond %{THE_REQUEST} ^GET\ /(https?://[^\ ]+)
RewriteRule ^https?:/ /index.php?var=%1 [R]
相关问题