Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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/HTTP://example.com 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.

share|improve this question
add comment

2 Answers

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]
share|improve this answer
    
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. –  Shane Madden Oct 25 '11 at 1:20
    
Here go the rules in my httpd.conf file : pastebin.com/2MEZtejU (is that what you asked for?) –  user88753 Oct 25 '11 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? –  Shane Madden Oct 25 '11 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. –  user88753 Oct 25 '11 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? –  user88753 Oct 25 '11 at 10:58
add comment
up vote 0 down vote accepted

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.

share|improve this answer
    
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. :) –  user88753 Oct 25 '11 at 14:57
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.