简体   繁体   English

.htaccess RewriteRule 将 http 重定向到 https 弄乱了 URL 中的 % 转义参数

[英].htaccess RewriteRule to redirect http to https messes up % escaped parameters in URL

I'm using something similar to the following in my .htaccess file to redirect all http requests to https :我在.htaccess文件中使用类似于以下内容的内容将所有http请求重定向到https

RewriteEngine on
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

That works, except for a situation when a URL is passed with escaped parameters, as such:这是有效的,除了使用转义参数传递 URL 的情况,例如:

http://www.example.com/download.php?go=app%20name

when redirected, it is mistakenly escaped again into:重定向时,它错误地再次转义为:

https://www.example.com/download.php?go=app%2520name

How do I fix this?我该如何解决?

Use NE or noescape flag in your rule:在您的规则中使用NEnoescape标志

RewriteEngine on

RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]

Make sure to clear your browser cache before testing the change.在测试更改之前,请确保清除浏览器缓存。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM