【问题标题】:https to http for some URLs with htaccesshttps 到 http 对于某些带有 htaccess 的 URL
【发布时间】:2014-03-15 00:38:28
【问题描述】:

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

所以我作为我的问题。

我想将一些 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 的 code-sn-p 解决我的问题。但我没有运气。它仍然停留在 SSL 上。这可能是因为 SSL 来自 Apache-Server Confixx 配置吗?

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

查询字符串不包含在 RewriteRule 的第一个参数中,或者可以与 %{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 /

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

【问题讨论】:

    标签: .htaccess http ssl https


    【解决方案1】:

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

    您可以通过将公共部分 (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]
    

    【讨论】:

    • 您好 Sumurai8,感谢您迄今为止的回复和帮助。但我仍然对这个问题持保留态度。也许您可以在我上面的答案中找到错误。
    • 您好,StackOverflow 不是论坛。因此,除非它确实解决了您的问题中概述的问题,否则您不应将我的回答“回复”作为您问题的答案。您可以使用新信息更好地编辑您的问题,并像您在此处所做的那样通过评论通知我。
    • @konzeptplus 您的 .htaccess 在哪里,它是否包含更多规则?那么它包含什么规则呢?
    • 嗨@Sumurai8。感谢你目前的帮助。对第二个答案感到抱歉。我没有意识到这一点。现在我懂了。我在第二个“答案”中更新了一些信息。提前致谢。 htaccess 在 root 上,漏洞代码在第二个答案更新中。谢谢
    • 嗨 Sumurai8,所有问题和有关它的更新现在都在 1 个问题中。会不会因为必须更改为 http 的 url 在注册区域中而无法正常工作?和/或因为 SSL 也被 cms 配置推送?
    猜你喜欢
    • 1970-01-01
    • 2012-07-11
    • 1970-01-01
    • 2014-06-11
    • 2015-02-13
    • 2023-03-03
    • 1970-01-01
    • 2011-03-19
    • 1970-01-01
    相关资源
    最近更新 更多