1

I have searched an .htaccess that redirects all the traffic from an Old Site to a New one (including HTTPS) but I have not found it.

Actually I have this:

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://www.OldDomain.com/$1 [R=301,L]

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

And this one works perfect for these situations:

http://OldDomain.com/                > https://www.NewDomain.com/
http://OldDomain.com/internal/       > https://www.NewDomain.com/internal/
http://www.OldDomain.com/            > https://www.NewDomain.com/
http://www.OldDomain.com/internal/   > https://www.NewDomain.com/internal/

https://OldDomain.com/               > https://www.NewDomain.com/
https://www.OldDomain.com/           > https://www.NewDomain.com/

But these situations with HTTPS don't:

https://OldDomain.com/internal/
https://www.OldDomain.com/internal/

What I have missing in my .htaccess?

Thanks

Gabrielizalo
  • 896
  • 1
  • 17
  • 29

2 Answers2

0

Try this -

  • Put this on root .htaccess of old : (old to new)

    Options +FollowSymlinks
    RewriteEngine on
    rewritecond %{http_host} ^domain.com [nc]
    rewriterule ^(.*)$ http://www.domain.com/$1 [r=301,nc]
    
  • Put this in the root .htaccess of new : (http to https)

    RewriteEngine on

    RewriteCond %{HTTPS} off

    RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

Refer : redirect all traffic to https

Community
  • 1
  • 1
Ani Menon
  • 27,209
  • 16
  • 105
  • 126
0

If the new domain is pointing to a diffrent web server, You can also use mod-alias instead of using mod-rewrite :

Add the following line to your olddomain/.htaccss :

Redirect 301 / https://www.newdomain.com/

This will forword all requests to the new domain.

Reference

https://httpd.apache.org/docs/current/mod/mod_alias.html

Amit Verma
  • 40,709
  • 21
  • 93
  • 115