.htaccess redirect https url to http

江枫思渺然 提交于 2019-12-12 02:00:03

问题


I have a website with some areas that use https, however I'm having problems changing a few https urls to http ones. This is what I need:

change this url url

https://www.domain.com/somefile.php?PossibleGetParameters

to this:

http://www.domain.com/somefile.php?PossibleGetParameters

This is what I have on my .htaccess:

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

With this condition all https urls are turned into http, and I only want this particular one to change. Is there any way to fix this?


回答1:


Sure ... just remove the exclamation mark ! from second condition -- in that position it negates the rule.

The final rule will be:

RewriteCond %{HTTPS} on
RewriteCond %{REQUEST_URI} ^/somefile.php
RewriteRule .* http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

I've simplified the rule a tiny bit (as you need it for a single URL only).

This rule may not work straight away as modern browsers do cache 301 redirects .. so browser may remember your previous attempts. Therefore clear browser caches and restart it before testing the rule (or try another browser).



来源:https://stackoverflow.com/questions/7432809/htaccess-redirect-https-url-to-http

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!