https for main domain and http for subdomain

匿名 (未验证) 提交于 2019-12-03 01:08:02

问题:

So i need very simple codes for .htaccess

I want to redirect all traffic to https in main domain and redirect all traffic to http in subdomain without WWW.

Right now i am using this code to redirect all traffic to https

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

So main domain should be like this: https://website.com

and subdomain should be like this: http://sub.website.com

I found many answers but very complicated, so need simple solution.

EDITED

Solution given by anubhava works great. Thanks for your solution.

回答1:

You can use:

RewriteEngine On  # maindomain -> https RewriteCond %{HTTPS} off RewriteCond %{HTTP_HOST} ^(?:www\.)?(website\.com)$ [NC] RewriteRule ^ https://%1%{REQUEST_URI} [R,L]  # subdomain -> http RewriteCond %{HTTPS} on RewriteCond %{HTTP_HOST} ^(?:www\.)?(sub\.website\.com)$ [NC] RewriteRule ^ http://%1%{REQUEST_URI} [R,L] 


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!