How to redirect example.com from HTTPS to HTTP, then HTTP example.com to newdomain.com?
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]
Related videos on Youtube
Admin
Updated on September 18, 2022Comments
-
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 tohttp://example.com
and then,http://example.com
redirects tohttp://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 over 12 yearsCan you post your
<VirtualHost>
configs? Looks like requests tohttps://wwwery.com
are being answered by thehttps://whatthenerd.com
vhost, and thus not redirecting. Requests tohttp://wwwery.com
are redirecting, but tonewdomain.com
and notwhatthenerd.com
- fix that in the config. -
Admin over 12 yearsHere go the rules in my httpd.conf file : pastebin.com/2MEZtejU (is that what you asked for?)
-
ravi yarlagadda over 12 yearsThose 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 over 12 yearsI 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 over 12 yearsThis 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 almost 8 yearsExcellent. Used this to redirect .com to whitewreath.org.au
-
alpham8 over 7 yearsMUCH 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
inRewriteRule
. Pretty much the same.