0

我正在尝试执行以下重定向:

Redirect 301 "/cgi-bin/teemz/teemz.cgi?board=_master&action=opentopic&topic=4&forum=The_Forum" "/content/1998-09-10/1004/wet-h2s---hic-concern---ae-amp"

这会导致内部服务器错误。你们能看出这段代码有什么问题吗?

4

2 回答 2

0

基本上你有一些非法字符,例如“/

您需要对每个参数的值进行编码。我不知道你怎么能用你正在使用的编程语言来做到这一点,但在 ASP.NET MVC 中,我们有相应的库。

 public ActionResult Index2()
    {
        var sb = new StringBuilder();
        foreach (var key in Request.QueryString.AllKeys)
            sb.AppendFormat("&{0}={1}", key, HttpUtility.UrlEncode(Request.QueryString[key]));
        var parameters = sb.Remove(0, 1);
        const string rawurl = "http://localhost:49534/home?";
        var url = string.Format("{0}{1}", rawurl, sb);
        return Redirect(url);
    }

编码后的参数将变为

board=_master&action=opentopic&topic=4&forum=The_Forum%22+%22%2fcontent%2f1998-09-10%2f1004%2fwet-h2s---hic-concern---ae-amp

但是你的浏览器地址栏会保留参数

"?board=_master&action=opentopic&topic=4&forum=The_Forum"+"%2fcontent%2f1998-09-10%2f1004%2fwet-h2s---hic-concern---ae-amp"

于 2013-01-02T09:37:32.200 回答
0

请记住 RewriteRule:

  • 与前导斜杠不匹配
  • 不匹配查询字符串

请改用此重写规则:

RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+cgi-bin/teemz/teemz\.cgi\?board=_master&action=opentopic&topic=4&forum=The_Fo‌​rum [NC]
RewriteRule ^ /content/1998-09-10/1004/wet-h2s---hic-concern---ae-amp [L,R=301]
于 2013-01-02T10:42:06.137 回答