.htaccess - 使用 htaccess 的某些 URL 的 https 到 http

标签 .htaccess http ssl https

我尝试了一些在一些问答中找到的代码提示,但我没有任何运气。

所以我作为我的问题。

我想将一些 URL 的形式从 https 重定向到 http。

我的一部分 htaccess 代码如下。但它不起作用,URL 仍然保留在 SSL 上。 主要的 SSL 直接来自服务器。

RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
RewriteCond %{HTTPS} on
RewriteCond %{REQUEST_URI} ^/index.php?lang=de&Itemid=231
RewriteCond %{REQUEST_URI} ^/index.php?lang=en&Itemid=337
RewriteCond %{REQUEST_URI} ^/index.php?lang=fr&Itemid=338
RewriteCond %{REQUEST_URI} ^/index.php?option=com_content&view=category&layout=blog&id=58&Itemid=231&lang=de
RewriteCond %{REQUEST_URI} ^/index.php?option=com_content&view=category&layout=blog&id=58&Itemid=337&lang=en
RewriteCond %{REQUEST_URI} ^/index.php?option=com_content&view=category&layout=blog&id=58&Itemid=338&lang=fr
RewriteRule .* http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

提前感谢您的帮助。


我试图用 Sumurai8 的代码片段解决我的问题。但我没有任何运气。它仍然停留在 SSL 上。会不会是因为 SSL 来自 Apache-Server Confixx 配置?

我还检查了缓存。此外,我无法将您的代码与简化代码一起使用。它说,它无法完成请求 -> 循环。

The query string is not included in the first argument of RewriteRule, or can be matched with %{REQUEST_URI}

是否需要添加新规则来匹配条件?

喜欢:

RewriteRule .* http://%{HTTP_HOST}%{QUERY_STRING} [R=301,L]

更新:

htaccess 文件位于 html 文件夹中。所以不在子文件夹中。

目前的孔代码如下:

Action php /cgi-php53/php
AddHandler php53 .php

RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
RewriteCond %{HTTPS} on
RewriteCond %{QUERY_STRING} ^/index.php?lang=de&Itemid=231 [OR]
RewriteCond %{QUERY_STRING} ^/index.php?lang=en&Itemid=337 [OR]
RewriteCond %{QUERY_STRING} ^/index.php?lang=fr&Itemid=338 [OR]
RewriteCond %{QUERY_STRING} ^/index.php?option=com_content&view=category&layout=blog&id=58&Itemid=231&lang=de [OR]
RewriteCond %{QUERY_STRING} ^/index.php?option=com_content&view=category&layout=blog&id=58&Itemid=337&lang=en [OR]
RewriteCond %{QUERY_STRING} ^/index.php?option=com_content&view=category&layout=blog&id=58&Itemid=338&lang=fr
RewriteRule .* http://%{HTTP_HOST}%{QUERY_STRING} [R=301,L]

无效条件和规则

#RewriteCond %{HTTP_HOST} ^chimia.ch
#RewriteRule (.*) http://scg.ch/$1 [R=301,L]

#RewriteCond %{HTTP_HOST} ^myow.ch
#RewriteRule (.*) http://scg.ch/$1 [R=301,L]

#RewriteCond %{HTTP_HOST} ^polycoll.ch
#RewriteRule (.*) http://scg.ch/$1 [R=301,L]

#RewriteCond %{HTTP_HOST} ^swiss-chem-soc.ch
#RewriteRule (.*) http://scg.ch/$1 [R=301,L]

#RewriteCond %{HTTP_HOST} ^youngchemists.ch
#RewriteRule (.*) http://scg.ch/$1 [R=301,L]

#RewriteCond %{HTTP_HOST} ^www.chimia.ch
#RewriteRule (.*) http://scg.ch/$1 [R=301,L]

#RewriteCond %{HTTP_HOST} ^www.myow.ch
#RewriteRule (.*) http://scg.ch/$1 [R=301,L]

#RewriteCond %{HTTP_HOST} ^www.polycoll.ch
#RewriteRule (.*) http://scg.ch/$1 [R=301,L]

然后是一些重定向,例如:

Redirect /cours/2014-aa1f https://scg.ch/index.php?option=com_superevents&redirect=category&catid=74&Itemid=525&task=group&view=details&id=2674&lang=en

Redirect /cours/2014-aa2f https://scg.ch/index.php?option=com_superevents&redirect=category&catid=74&Itemid=525&task=group&view=details&id=2678&lang=en

Redirect /cours/2014-aa3f https://scg.ch/index.php?option=com_superevents&redirect=category&catid=74&Itemid=525&task=group&view=details&id=2689&lang=en

更多的重定向

Redirect /roempp https://scg.ch/index.php?option=com_content&view=article&id=926:roempp-online-special-offer-for-scs-members&catid=9:scg-news&Itemid=112&lang=en

Redirect /login https://scg.ch/index.php?option=com_comprofiler&task=login&lang=en


ErrorDocument 404 /

提前感谢您的更多帮助。问候

最佳答案

除了一件事,你的规则似乎很好。查询字符串不包含在RewriteRule的第一个参数中,或者可以与%{REQUEST_URI}匹配。此外,正则表达式中的 ? 字符表示“匹配前一个字符 0 次或 1 次”,而 . 字符表示“匹配任何字符”。您需要将其与 %{QUERY_STRING} 匹配或将其与 %{THE_REQUEST} 匹配。

您可以通过将公共(public)部分 (index.php) 移动到 RewriteRule 的第一个参数来简化它,在描述每个可能的查询字符串的所有条件之前启用所需的 HTTPS。通过使用 OR 标志链接这些条件,只要其中之一为真,其中只有一个必须为真。

RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

RewriteCond %{HTTPS} on
RewriteCond %{QUERY_STRING} ^lang=de&Itemid=231$ [OR]
RewriteCond %{QUERY_STRING} ^lang=en&Itemid=337$ [OR]
RewriteCond %{QUERY_STRING} ^lang=fr&Itemid=338$ [OR]
RewriteCond %{QUERY_STRING} ^option=com_content&view=category&layout=blog&id=58&Itemid=231&lang=de$ [OR]
RewriteCond %{QUERY_STRING} ^option=com_content&view=category&layout=blog&id=58&Itemid=337&lang=en$ [OR]
RewriteCond %{QUERY_STRING} ^option=com_content&view=category&layout=blog&id=58&Itemid=338&lang=fr$
RewriteRule ^index\.php$ http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

关于.htaccess - 使用 htaccess 的某些 URL 的 https 到 http,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21799902/

相关文章:

PHP 5.6 字符集头回到 ISO-8859-1?

java - 打开 url.openstream 抛出无效的 http 响应

http - chart.apis.google.com 返回错误 400

ssl - 在 Archlinux 中删除 DST_Root_CA_X3

.htaccess - 我可以使用 DNS 或 .htaccess 将子域重定向到其他站点吗?

javascript - 301 重定向www/.htaccess

http - 使用 `UrlFetchApp` 的 PUT 请求返回 'Bad Request' 但 Google Apps 脚本之外的相同请求有效

java - 将证书添加到 AWS EC2 客户端

Java SSL套接字 : PKIX path building failed

php - 如何在 PHP 中将数据库 URL 显示为网页 URL