How to write htaccess for subdomain redirection to https

梦想与她 提交于 2019-12-24 05:48:25

问题


How to write htaccess rules for redirect example.com to www.example.com and also we have number of subdomains for example subdomain.example.cpm so i need to redirect it to https://subdomain.example.com. but when i write htaccess rules it is going to loop. please send how to write conditions for this.


回答1:


Put this code in your DOCUMENT_ROOT/.htaccess file:

RewriteEngine On

# example.com to www.example.com
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE]

# http to https for subdomains
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE]


来源:https://stackoverflow.com/questions/20840669/how-to-write-htaccess-for-subdomain-redirection-to-https

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