3

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.

2 Answers 2

2

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] 
6
  • Can you post your <VirtualHost> configs? Looks like requests to https://wwwery.com are being answered by the https://whatthenerd.com vhost, and thus not redirecting. Requests to http://wwwery.com are redirecting, but to newdomain.com and not whatthenerd.com - fix that in the config. Commented Oct 25, 2011 at 1:20
  • Here go the rules in my httpd.conf file : pastebin.com/2MEZtejU (is that what you asked for?) Commented Oct 25, 2011 at 1:51
  • Those are some ominous capital letters, that's for sure. I'm only seeing the one actual vhost on :443 - is there not one in place for wwwery.com:443? Commented Oct 25, 2011 at 1:58
  • I actually don't know about these. I will contact my web host and see what they can do about it. Kindly check back this thread tomorrow. I will post the update here (any changes). Thanks. Commented Oct 25, 2011 at 2:04
  • My webhost took all the time in the world to tell me that it's not HTTPS redirect an addon domain to another domain under the same Cpanel account, as they both share a common SSL certificate. Looks like the only way is to create a separate account for the addon domain? Commented Oct 25, 2011 at 10:58
1

Thanks for all the help @Shane Madden. Got it all worked out. This was the .htaccess (of example.com) rule that I was and am using:

Options +FollowSymLinks RewriteEngine On RewriteCond %{HTTP_HOST} ^.*example\.com$ [NC] RewriteRule ^(.*)$ http://newdomain.com/$1 [R=301,L] 

The reason it didn't work before was because the two domains were using the same SSL certificate (as one is an addon domain under the Cpanel account of another domain). "HTTPS redirection does not work for addon domains."

So, what I did was create a new cpanel account for example.com. That is, get a separate SSL cert for example.com As simple as that.

2
  • This only redirects HTTP/HTTPS://example.com to newdomain.com. The answer by @Shane Madden redirects every single thing on the server to newdomain.com. Use whatever suits you best. :) Commented Oct 25, 2011 at 14:57
  • MUCH thanks, helped us, too. All the others said it is impossible, but no, as we can see it is not! :-) I am redirecting every request from the old domain to the new one with fixed https in RewriteRule. Pretty much the same. Commented Jan 27, 2017 at 14:50

You must log in to answer this question.