Title: .htaccess : domain change   switch to HTTPS
Last modified: August 31, 2016

---

# .htaccess : domain change switch to HTTPS

 *  [Robin Labadie](https://wordpress.org/support/users/robin-labadie/)
 * (@robin-labadie)
 * [10 years, 1 month ago](https://wordpress.org/support/topic/htaccess-domain-change-switch-to-https/)
 * Hey there !
 * Self hosted here, basic LAMP server.
    I recently switched from a domain to another
   in addition to switching to HTTPS.
 * For everything to be perfect, i’d need those redirections :
    [http://(www](http://(www).)
   old.org/${anything} > [https://www.new.org/$](https://www.new.org/$){anything}
   [http://(www](http://(www).)new.org/${anything} > [https://www.new.org/$](https://www.new.org/$){
   anything}
 * Here is what i did in my .htaccess for now
 *     ```
       # BEGIN WordPress
       <IfModule mod_rewrite.c>
               RewriteEngine On
               RewriteBase /
               # Redirect mesnie.org to terageek.org
               RewriteCond %{HTTP_HOST} ^(?:www\.)mesnie\.org$ [NC]
               RewriteRule ^ http://terageek.org%{REQUEST_URI} [L,R=301]
               # Enforce HTTPS
               RewriteCond %{HTTPS} Off
               RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
               RewriteRule ^index\.php$ - [L]
               RewriteCond %{REQUEST_FILENAME} !-f
               RewriteCond %{REQUEST_FILENAME} !-d
               RewriteRule . /index.php [L]
       </IfModule>
       # END WordPress
       ```
   
 * What works :
    Now, the old domain switches right to the new keeping the right
   URL. Visiting the new domain adds the www if needed.
 * What doesn’t work :
    The HTTP to HTTPS doesn’t work. Going to [http://old.org/$](http://old.org/$){
   anything} switches to [http://new.org/$](http://new.org/$){anything} instead 
   of [https://www.new.org/$](https://www.new.org/$){anything}, until of course 
   visitors click a link.
 * So, any idea on how to tweak my .htaccess ?

Viewing 3 replies - 1 through 3 (of 3 total)

 *  [550](https://wordpress.org/support/users/550-1/)
 * (@550-1)
 * [10 years, 1 month ago](https://wordpress.org/support/topic/htaccess-domain-change-switch-to-https/#post-7245055)
 * **Force HTTPS**
 * RewriteEngine on
    RewriteCond %{HTTPS} !on RewriteRule (.*) [https://%](https://%){
   HTTP_HOST}%{REQUEST_URI}
 *  Thread Starter [Robin Labadie](https://wordpress.org/support/users/robin-labadie/)
 * (@robin-labadie)
 * [10 years, 1 month ago](https://wordpress.org/support/topic/htaccess-domain-change-switch-to-https/#post-7245175)
 * Thanks for the try.
    So now it works almost as intended for the current domain.
   [http://newdomain.org](http://newdomain.org) and [http://www.newdomain.org](http://www.newdomain.org)
   redirect to the https versions. But it’s working only for the home page. Not 
   the sub pages.
 * On the old domains, i got some errors.
    “The document has moved here.
 * Additionally, a 500 Internal Server Error error was encountered while trying 
   to use an ErrorDocument to handle the request.”
 * Might be an issue with what’s next ? I tried changing order with no success.
 * Maybe it’s time for me to get some more knowledge about .htaccess. Unless somebody
   pops out with a perfect solution :p
 *  [Ravikumar Patel](https://wordpress.org/support/users/ravipatel/)
 * (@ravipatel)
 * [10 years ago](https://wordpress.org/support/topic/htaccess-domain-change-switch-to-https/#post-7245399)
 * **Redirect to https and www**
 *     ```
       # Canonical https/www
       <IfModule mod_rewrite.c>
       	RewriteCond %{HTTPS} off [OR]
       	RewriteCond %{HTTP_HOST} !^www\. [NC]
       	RewriteCond %{HTTP_HOST} ^(.*)$  [NC]
       	RewriteRule (.*) https://www.%1/$1 [R=301,L]
       </IfModule>
       ```
   
 * **Redirect to https and non-www**
 *     ```
       # Canonical HTTPS/WWW
       <IfModule mod_rewrite.c>
       	RewriteCond %{HTTPS} off [OR]
       	RewriteCond %{HTTP_HOST} ^www\.example\.com [NC]
       	RewriteRule (.*) https://example.com/$1 [L,R=301]
       </IfModule>
       ```
   

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘.htaccess : domain change switch to HTTPS’ is closed to new replies.

## Tags

 * [domain-name](https://wordpress.org/support/topic-tag/domain-name/)
 * [htaccess](https://wordpress.org/support/topic-tag/htaccess/)
 * [HTTPS](https://wordpress.org/support/topic-tag/https/)
 * [redirect](https://wordpress.org/support/topic-tag/redirect/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 3 replies
 * 3 participants
 * Last reply from: [Ravikumar Patel](https://wordpress.org/support/users/ravipatel/)
 * Last activity: [10 years ago](https://wordpress.org/support/topic/htaccess-domain-change-switch-to-https/#post-7245399)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
