Alok Uniyal

Alok Uniyal

  • 1.3k
  • 394
  • 22.6k

Redirect multiple website in single .htacess file

Dec 29 2018 12:06 AM
I have two websites example1.com and example2.com hosting in same server.
 
example1.com is https secure and should redirect to https://www.example1.com
example2.com is not secure it should redirect to http://www.example2.com
 
Currently I am using
 
# ensure www.
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# ensure https
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
 
But it is redirecting both URLs.
Please help how to write different RewriteRule for both URLs in single .htacess file.

Answers (3)