重定向到具有特定域的.htaccess的HTTPS

重定向到具有特定域的.htaccess的HTTPS,.htaccess,redirect,https,.htaccess,Redirect,Https,我目前有两个域可以访问我服务器上的同一文件夹:metrikstudios.com和ziced.com 我希望通过http://metrikstudios.com进入的用户被重定向到https://metrikstudios.com,而通过http://metrikstudios.com进入的用户不被重定向到 我目前在.htaccess上有这个 RewriteEngine On RewriteCond %{HTTPS} off RewriteRule (.*) https://%{HTTP_HOS

我目前有两个域可以访问我服务器上的同一文件夹:metrikstudios.com和ziced.com

我希望通过http://metrikstudios.com进入的用户被重定向到https://metrikstudios.com,而通过http://metrikstudios.com进入的用户不被重定向到

我目前在.htaccess上有这个

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

谢谢

您只需添加另一个RewriteCond即可检查主机是否为metrikstudios.com

RewriteCond %{HTTP_HOST} ^metrikstudios\.com [NC]
它应该是这样的:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^metrikstudios\.com [NC]
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI}
Linux和cPanel基于Linux的帐户使用 .htaccess

处理重定向的文件。 注意:如果需要创建.htaccess文件,可以使用 控制面板的文件管理器(Web和Classic/cPanel)

在.htaccess文件中使用以下代码会自动将访问者重定向到站点的HTTPS版本:

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
If you have an existing .htaccess file:
<configuration>
<system.webServer>
<rewrite>
    <rules>
    <rule name="HTTP to HTTPS redirect" stopProcessing="true"> 
    <match url="(.*)" /> 
    <conditions> 
        <add input="{HTTPS}" pattern="off" ignoreCase="true" />
    </conditions> 
    <action type="Redirect" redirectType="Permanent" url="https://{HTTP_HOST}/{R:1}" />
</rule>   
    </rules>
</rewrite>
</system.webServer>
</configuration>
不要在发动机上重复重写。 确保以RewriteCond和RewriteRule开头的行立即遵循已存在的RewriteEngine On。

视窗与普莱斯克 基于Windows的帐户使用web.config文件处理重定向。 注意:如果需要创建web.config文件,可以使用控制面板的文件管理器(web&Classic/Plesk)。

在web.config文件中使用以下代码会自动将访问者重定向到网站的HTTPS版本:

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
If you have an existing .htaccess file:
<configuration>
<system.webServer>
<rewrite>
    <rules>
    <rule name="HTTP to HTTPS redirect" stopProcessing="true"> 
    <match url="(.*)" /> 
    <conditions> 
        <add input="{HTTPS}" pattern="off" ignoreCase="true" />
    </conditions> 
    <action type="Redirect" redirectType="Permanent" url="https://{HTTP_HOST}/{R:1}" />
</rule>   
    </rules>
</rewrite>
</system.webServer>
</configuration>

如果您有一个现有的web.config文件:

确保您有以下部分(即开始和结束标签): system.webServer(包含重写) 重写(包含规则) 规则(包含一个或多个规则节) 插入任何不存在的部分。 在规则部分中插入整个规则部分,包括匹配、条件和操作。
注意:您正在将规则(不带“s”)插入规则(带“s”)部分。

上面接受的解决方案仅将
非www
域从
http
重定向到
https

如果要将域的
www
non-www
版本重定向到
ssl
请将以下
RewriteCond
放在http-to-https规则的正上方或在
RewriteCond%{https}关闭之前
行:

RewriteCond %{HTTP_HOST} ^(www\.)?example.com$ [NC]
下面是将特定域重定向到https的完整规则

RewriteEngine on

# First we will check the host header (url)
#if it's www.example.com or example.com
RewriteCond %{HTTP_HOST} ^(www\.)?example.com$ [NC]
# now we will check the https header
# if https is off (Is non-ssl)
RewriteCond %{HTTPS} off
#redirect the request to https
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [NE,L,R=301]

有时,您可能希望仅在live server上重定向,并保持其本地设置不变。例如,如果您在本地计算机上注册了名为
www.mysite.loc
的本地主机,并在此主机上设置了项目的本地实例

在这种情况下,这也可能对某人有所帮助:

RewriteEngine On
RewriteCond %{HTTPS} =off
RewriteCond %{HTTP_HOST} !.loc$ [NC]
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [R,L]
其中
!。loc$
-如果主机以
.loc
结尾,则忽略重定向到https的规则