如何防止子域重定向到https

mai*_*ido 2 php regex .htaccess mod-rewrite redirect

我想将网站重定向到https://但我不希望重定向子域.当我输入:dev.mycreditstatus.co.za时,它会被重定向到https://即使我不想要它.

这是我的.htaccess(public_ssl)中的代码:

ErrorDocument 404 https://mycreditstatus.co.za/404.php

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On

RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} ^imupost\.co\.za$ [NC]
RewriteRule ^ http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
Run Code Online (Sandbox Code Playgroud)

.htaccess(public_html):

ErrorDocument 404 https://mycreditstatus.co.za/404.php

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} !^/(pp5fdr) [NC]
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
Run Code Online (Sandbox Code Playgroud)

我应该做些什么修改来使这个工作?谢谢!

Mic*_*ski 5

public_html.htaccess中,您没有条件将其限制为仅限主域(这假设您的子域根植于同一目录中).您需要另一个RewriteCond只匹配主域名:

ErrorDocument 404 https://mycreditstatus.co.za/404.php

RewriteEngine On
RewriteCond %{HTTPS} off
# Only redirect to https if the main domain (no subdomain) is matched
# case-insensitively in HTTP_HOST
RewriteCond %{HTTP_HOST} ^mycreditstatus\.co\.za$ [NC]
RewriteCond %{REQUEST_URI} !^/(php05142013) [NC]
# added flags...
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
Run Code Online (Sandbox Code Playgroud)