How to redirect example.com from HTTPS to HTTP, then HTTP example.com to newdomain.com

.htaccess301-redirecthttphttps

As of now I use this rule (in .htaccess of example.com) to redirect HTTPS/HTTP example.com to newdomain.com:

Options +FollowSymLinks
RewriteEngine on
RewriteRule (.*) http://newdomain.com/$1 [R=301,L]

And from searching, I found that the following rule redirects HTTPS to HTTP:

RewriteEngine On
RewriteCond %{HTTPS} on
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI}

How do I combine these, so that – – https://example.com redirects to http://example.com and then, http://example.com redirects to http://newdomain.com.

I cannot explain why I am not asking for something like this – – HTTPS/ redirects to http://newdomain.com. In short, I have searched and asked, and the rules suggested aren't working, probably coz I am using a self-signed cert, and the same cert for the two domains (example.com is an addon domain, and newdomain.com is the main domain). Please advise, if that makes sense.

Best Answer

Interesting requirement, I'm not sure I understand why you'd do this - it's just making it take two 301 responses to get to newdomain.com instead of one.. But, I suppose this'll do it:

RewriteEngine on

# First rule - if this is an SSL connection, then redirect
# to http://example.com then stop processing other rules
RewriteCond %{HTTPS} on
RewriteRule (.*) http://example.com/$1 [R=301,L]

# Second rule - all other requests, redirect to http://newdomain.com.
RewriteRule (.*) http://newdomain.com/$1 [R=301,L]