从index.php?....重写为index.php%3F .... html

时间:2013-02-11 18:37:19

标签: apache mod-rewrite wget

我正在尝试用这个wget行创建一个静态的b2evolution站点:

  wget -nv -b -m -k -p -E -erobots=off --tries=5 --exclude-directories=calendar,users,user --domains directory http://site.com

它产生这样的文件:

  index.php?blog=2&cat=21.html

尝试访问此网址:

  http://site.com/index.php?blog=2&cat=21.html

我在浏览器上发现了这个错误:

  Not Found
  The requested URL /index.php was not found on this server.

和error.log上的这个:

  [Mon Feb 10 19:02:49 2013] [error] [client xx.xx.xx.xx] script '/var/www/site.com/htdocs/index.php' not found or unable to stat, referer: http://site.com/index.php

但我可以使用%3F代替“?”:

  http://site.com/index.php%3Fblog=2&cat=21.html

我的范围允许使用旧的url(带'?')访问网站,使用apache rewrite_mod修改'?' '%3F'。我试过了:

  RewriteRule ^index.php\? index.php\%3F [QSA,NE]

但我在日志中发现了这个错误:

  Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace.

用mod_rewrite或其他wget参数解决任何想法吗?

2 个答案:

答案 0 :(得分:1)

如果文件名包含?,则以下规则应该有效。

RewriteEngine On
RewriteCond %{QUERY_STRING} (.+)
RewriteRule ^(index\.php)$ $1\%3F%1 [L]

它的工作原理如下:

  • RewriteRule评估 优先 ,匹配存储在$ 0,$ 1,...
  • 成功后,评估RewriteCond并将匹配项存储在%0,%1,...
  • 最后,两个比赛合并
  • 文字%字符转义为\%(因为%n用于RewriteCond反向引用所必需的)
  • %3F?的网址编码形式,否则表示查询字符串的开头
  • .+用于匹配非空查询字符串

答案 1 :(得分:0)

请参阅--restrict-file-names选项。虽然不完全是出于这个特定目的,但是--restrict-file-names = windows可能会帮助你:

  

- 限制文件 - 名称=模式

     

更改远程网址中找到的字符必须在转换过程中进行转义   生成本地文件名。 [...]

     

当给出“windows”时,Wget会转义字符\,|,/,:,?,“,   *,<,>,以及范围0--31和128--159中的控制字符。除此之外,Windows模式下的Wget使用+而不是:to   在本地文件名中分隔主机和端口,并使用@而不是?至   将文件名的查询部分与其余部分分开。因此,   一个URL,保存为www.xemacs.org:4300/search.pl?input=blah   在Unix模式下将保存为   在Windows模式下www.xemacs.org+4300/search.pl@input=blah。

相关问题