【问题标题】:Mod rewrite, redirect all to https except specific URI and redirect that URI from https to httpMod重写,将除特定URI之外的所有重定向到https并将该URI从https重定向到http
【发布时间】:2023-03-17 00:41:02
【问题描述】:

所以我一直碰壁尝试了许多不同的选项和配置。我正在尝试将我的网站重定向到 https,但我希望将其从 https 重定向到 http 然后保持 http 的特定 URI 除外。我将不胜感激任何帮助。这是通过虚拟主机配置完成的。以下是我与 ssl.conf 和 mysite.conf 配对尝试过的设置。但是,我不断收到重定向循环或无法加载的页面。

mysite.conf

RewriteEngine on
RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_URI} !/example
RewriteRule ^(.*)$ https://my.site.com$1 [R,L]

RewriteCond %{HTTPS} !=on
RewriteCond %{REQUEST_URI} ^(/|page1|page2)
RewriteRule ^(.*)$ https://my.site.com$1 [R,L]

RewriteCond %{HTTPS} !=on
RewriteCond %{REQUEST_URI} !=/example
RewriteRule ^(.*)$ https://my.site.com$1 [R,L]

RewriteCond %{REQUEST_URI} =/example
RewriteRule ^(.*)$ http://my.site.com$1 [R,L]

加上上述之一。

然后在 ssl.conf 中

RewriteEngine on
RewriteCond %{REQUEST_URI} =/example
RewriteRule ^(.*)$ http://my.site.com$1 [R,L]

【问题讨论】:

    标签: apache mod-rewrite redirect httpd.conf


    【解决方案1】:

    这应该为你做。首先放置最具体的规则(/example)。

    RewriteEngine on
    
    RewriteCond %{HTTPS} =on
    RewriteRule ^/?example$ http://my.site.com/example [R=301,L]
    
    RewriteCond %{HTTPS} !=on
    RewriteCond %{REQUEST_URI} !^/?example$
    RewriteRule ^/?(.*)$ https://my.site.com/$1 [R=301,L]
    

    这应该在服务器 (.conf) 或目录 (.htaccess) 上下文中工作。

    【讨论】:

    • 这行得通但是有一个额外的问题,一旦我使用配置,我可以注意到,有一个额外的 URI 被调用,它不是添加附加条件语句的排除列表的一部分工作。谢谢迈克。
    猜你喜欢
    • 1970-01-01
    • 2013-04-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-12-17
    • 2016-09-16
    • 2017-06-13
    相关资源
    最近更新 更多