简体   繁体   English

如何将所有流量重定向到https而不是特定文件夹?

[英]How to redirect all traffic to https but a specific folder?

This is what I'm using right now to redirect all traffic to https: 这就是我现在用来将所有流量重定向到https的方式:

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

I would like to have this configuration but exclude one particular folder. 我想要这种配置,但要排除一个特定的文件夹。 The reason I'm doing this is that I have installed an add-on domain on the current hosting account and while the main domain has an SSL certificate installed, the one that I have recently added doesn't. 我这样做的原因是,我在当前主机帐户上安装了一个附加域,而主域中已安装了SSL证书,而我最近添加的域却没有。

Adding the addon domain creates a folder inside the root folder of the primary domains and because I'm redirecting all traffic through the htaccess configuration, it also tries to access the https version of the new addon domain. 添加插件域会在主域的根文件夹内创建一个文件夹,并且由于我通过htaccess配置重定向所有流量,因此它还会尝试访问新插件域的https版本。

You can exclude a folder using a RewriteCond : 您可以使用RewriteCond排除文件夹:

RewriteEngine On

RewriteCond %{HTTPS} off
RewriteCond  %{THE_REQUEST} !/someFolder/ [NC]
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]

You need to add a condition into it, so use this instead: 您需要在其中添加一个条件,因此可以使用以下条件:

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} !^/foldername
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

Clear your cache before testing this. 测试之前清除您的缓存。

If I read your question correctly, you would like to redirect all traffic that hits your site to https://, except for a single folder, right? 如果我正确阅读了您的问题,您希望将所有访问您网站的流量重定向到https://,除了单个文件夹外,对吗?

If that's the case, this should work: 如果是这样,这应该可行:

    RewriteEngine On
    RewriteCond %{HTTPS} off
    RewriteCond %{REQUEST_URI} !^/<folder-name>/
    RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI}  [R,L]

Just replace with the name of the folder you want to exclude. 只需替换为要排除的文件夹的名称即可。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM