【问题标题】:htacess url rewrite rule failing when url passed as parameter当 url 作为参数传递时,htaccess url 重写规则失败
【发布时间】:2012-11-09 16:42:03
【问题描述】:

我有这个 URL 重写规则

RewriteRule ^(send-your-request.*)$ / [NC,L,QSA,R=301]

它应该基本上只是从 URL 中删除“/send-your-request”(即用域中的查询字符串参数重写它,即

http://example.com/send-your-request/?a_aid=rocketnews24&pname=just%20a%20test

被改写为:

http://example.com/?a_aid=rocketnews24&pname=just%20a%20test

在这种情况下它可以工作,但是如果我添加最后一个参数,它就会停止工作

http://example.com/send-your-request/?a_aid=rocketnews24&pname=just%20a%20test&plink=http%3A%2F%2Fradio-eva.jp%2Fshop%2Fproducts%2Fdetail.php%3Fproduct_id%3D82

谁能告诉我一个可以处理所有查询字符串参数的更好的重写规则?

编辑 这是我的其他规则,但我在第一个规则上有“L”,所以它应该停止处理吧?

RewriteRule ^(send-your-request.*)$ / [NC,QSA,R=301,L]
Redirect 301 /products http://whiterabbitexpress.com/
RewriteRule ^index\.php$ - [L]
RewriteCond %{QUERY_STRING} ^(.*)q=(.*)$
RewriteRule ^(.*)$ $1?%1s=%2 [L,R=301] 
RewriteRule ^catalogsearch/result/?$ / [NC,QSA,L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

【问题讨论】:

  • 额外的查询字符串参数没有理由引起问题,你可以在这里测试它htaccess.madewithlove.be,它似乎重写就好了。
  • 您可以在我的网站上对其进行测试:'whiterabbitexpress.com/send-your-request/…` 直到最后一个参数都可以正常工作。我现在正在用我的其他规则更新帖子。但它们应该没有任何影响吧?
  • 可能是 mod_rewrite 中未在测试工具中建模的错误。
  • 不起作用。耶稣。我该怎么办?只需等待 2 天即可添加赏金?或者在 odesk.com 上雇用某人?
  • 可能是防止代码注入什么的安全功能

标签: .htaccess url-rewriting


【解决方案1】:

已解决:这是一个旨在防止注入的 Mod_security 规则。

SecRule REQUEST_URI "=(?:ogg|gopher|data|php|zlib|(?:ht|f)tps?)://" \ "capture,id:340165,t:none,t:urlDecodeUni,t:replaceNulls,t:compressWhiteSpace,t:lowercase,rev:275,severity:2,msg:'Atomicorp.com 不支持的延迟规则:未编码的可能远程文件注入尝试 URI (AE)',logdata:'%{MATCHED_VAR}'"

能够通过 ConfigServer ModSecurity Control 修改规则。

【讨论】:

    【解决方案2】:

    没有承诺,但这里有一个替代方案,应该做同样的事情,但值得一试。重写中的? 会剥离QueryString,然后%1 后向引用会重新追加它。

    RewriteBase /
    RewriteCond %{QUERY_STRING} (.*)
    RewriteRule ^send-your-request/?$ /?%1 [NC,R=301,L]
    

    值得注意的是,QueryString 会在重写时自动传递,如果 ? 出现在您的重写中,QSA 修饰符只会附加一个附加参数 - 如果您省略 QSA 并在其中包含 ?重写,它将剥离现有的 QueryString。您也可以尝试离开QSA

    RewriteBase /
    RewriteRule ^send-your-request/?$ / [NC,R=301,L]
    

    【讨论】:

    • 谢谢,但是,不好。相同的结果:没有最终参数可以工作,但不能使用它...尝试发布到 ServerFault...谢谢您的尝试!
    猜你喜欢
    • 2011-12-06
    • 2016-11-19
    • 1970-01-01
    • 1970-01-01
    • 2013-11-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多