简体   繁体   English

我想使用 htaccess 将特定 url 重定向到非 https

[英]I want to redirect specific url to non https using htaccess

my current htaccess is:-我目前的 htaccess 是:-

<IfModule mod_rewrite.c>
   RewriteEngine on
   RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
   RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
</IfModule>

i want to add rule to htaccess for url like https://www.example.com/abc/arg1/arg2 should redirect to http://www.example.com/abc/arg1/arg2 for this https://www.example.com/abc/ * it should redirect to non-https format with keeping all arguments.我想为像https://www.example.com/abc/arg1/arg2这样的 url 添加规则到 htaccess 应该重定向到http://www.example.com/abc/arg1/arg2这个https://www .example.com/abc/ * 它应该重定向到非 https 格式并保留所有参数。

Use below rule, check after clearing your cache.使用以下规则,清除缓存后检查。

RewriteCond %{REQUEST_URI} ^/abc/(.*) [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

Edit: Please try with below rule,编辑:请尝试以下规则,

RewriteCond %{REQUEST_URI} !^/abc/(.*) [NC]
RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

In above rule we are appending https to all url which are not starting with abc/(.*) you have to use this rewritecond where your original https rule exists.在上述规则中,我们将 https 附加到所有不以abc/(.*)开头的 url,您必须在原始 https 规则存在的地方使用此rewritecond

If you want to redirect all https requests starting with abc/ to http, you must check for both abc/ and HTTPS如果要将所有以abc/开头的 https 请求重定向到 http,则必须同时检查abc/HTTPS

RewriteCond %{HTTPS} on
RewriteRule ^abc/ http://www.example.com%{REQUEST_URI} [R,L]

When everything works as it should, you may replace R with R=301 ( permanent redirect ).当一切正常时,您可以将R替换为R=301永久重定向)。 Never test with R=301 .切勿使用R=301测试。

I am not sure how you achieve the job, but the following should be working perfectly for you.我不确定你是如何完成这项工作的,但以下内容应该非常适合你。

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

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

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