Reputation: 923
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.
Upvotes: 2
Views: 324
Reputation: 785146
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]
Upvotes: 2