htaccess的重定向HTTPS URL到http重定向、htaccess、HTTPS、http

2023-09-02 10:11:06 作者:愛上妳怎麽辦

我有与使用https一些地区的网站,但我有问题,改变了几HTTPS URL中到http的。这正是我需要的:

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:

更改此URL网址

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

这样:

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

这是我对我的.htaccess:

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]

有了这个条件的所有HTTPS URL中都变成了HTTP,而我只想要这个特殊的改变。有什么办法解决这一问题?

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?

推荐答案

当然...只是删除感叹号 从第二个条件 - 在该位置它否定该规则。

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

最终规则将是:

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

我已经简化了规则的一点点(因为你需要它的单个URL只)。

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

该规则可能无法马上为现代的浏览器做缓存301重定向..所以浏览器可能会记住你的previous尝试。因此,清除浏览器缓存和测试规则之前重新启动(或尝试使用其他浏览器)。

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).