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

30,704

Solution 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.

Solution 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]
Share:
30,704

Related videos on Youtube

Admin
Author by

Admin

Updated on September 18, 2022

Comments

  • Admin
    Admin over 1 year

    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.

  • ravi yarlagadda
    ravi yarlagadda over 12 years
    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.
  • Admin
    Admin over 12 years
    Here go the rules in my httpd.conf file : pastebin.com/2MEZtejU (is that what you asked for?)
  • ravi yarlagadda
    ravi yarlagadda over 12 years
    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?
  • Admin
    Admin over 12 years
    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.
  • Admin
    Admin over 12 years
    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. :)
  • Steve
    Steve almost 8 years
    Excellent. Used this to redirect .com to whitewreath.org.au
  • alpham8
    alpham8 over 7 years
    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.