Apache Rewrite:始终使用 HTTPS(如何添加例外)

发布于 2024-09-09 10:58:51 字数 811 浏览 2 评论 0原文

在 mydomain.com 上,我目前将所有 apache conf 文件保存在:

/etc/httpd/conf.d/

在那里我有一个名为 alwaysHttps.conf 的文件,其中包含:

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

我有一堆虚拟主机,对于网站上的一个域: myotherdomain.com 我想要关闭自动重定向。是否可以设置重定向到 https 的例外,而不必删除全局的alwaysHttps.conf?

<VirtualHost *:80> 
    DocumentRoot /home/webadmin/myotherdomain.com/html 
    ServerName myotherdomain.com 
    CustomLog "/home/webadmin/myotherdomain.com/access_log" "combined" 
    ErrorLog "/home/webadmin/myotherdomain.com/error_log" 
    <Directory /home/webadmin/myotherdomain.com/html> 
        Options Includes FollowSymLinks 
        AllowOverride All 
    </Directory> 
</VirtualHost> 

On mydomain.com, I currently keep all of my apache conf files in:

/etc/httpd/conf.d/

In there I have a file called alwaysHttps.conf that contains:

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

I have a bunch of virtualhosts, and for one domain on the site: myotherdomain.com I would like to turn off the auto redirect. Is it possible to setup an exception to the redirect to https, rather than having to get rid of the global alwaysHttps.conf?

<VirtualHost *:80> 
    DocumentRoot /home/webadmin/myotherdomain.com/html 
    ServerName myotherdomain.com 
    CustomLog "/home/webadmin/myotherdomain.com/access_log" "combined" 
    ErrorLog "/home/webadmin/myotherdomain.com/error_log" 
    <Directory /home/webadmin/myotherdomain.com/html> 
        Options Includes FollowSymLinks 
        AllowOverride All 
    </Directory> 
</VirtualHost> 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

嗫嚅 2024-09-16 10:58:51
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} !myotherdomain\.com
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [QSA]
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} !myotherdomain\.com
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [QSA]
坚持沉默 2024-09-16 10:58:51

极好的!

在我的 http.conf 中,我有:

NameVirtualHost  *:80
NameVirtualHost  *:443

Listen 8033

侦听 8033 的原因是因为我使用 OpenVPN 的功能来双重使用端口 80。一旦我更改了一切,

<VirtualHost *:80>  to 
<VirtualHost *:8033> 

一切就正常了。

但奇怪的是,为什么我的所有其他虚拟域和 *.conf 文件都可以工作,即使它们有而不

<VirtualHost *:80> 

知道

<VirtualHost *:8033>. 

为什么会出现这种情况?

Fantastic!

In my http.conf I have:

NameVirtualHost  *:80
NameVirtualHost  *:443

Listen 8033

The reason for the listen on 8033 was because I am using OpenVPN's feature to dual use port 80. Once I changed my

<VirtualHost *:80>  to 
<VirtualHost *:8033> 

everything worked.

The curious thing though is why all of my other virtual domains and *.conf files work even though they have

<VirtualHost *:80> 

and not

<VirtualHost *:8033>. 

Any idea why that would be the case?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文