• 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 :
    https://(www.)old.org/${anything} > https://www.new.org/${anything}
    https://(www.)new.org/${anything} > 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 ^ https://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 https://old.org/${anything} switches to https://new.org/${anything} instead of 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)
  • Force HTTPS

    RewriteEngine on
    RewriteCond %{HTTPS} !on
    RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

    Thread Starter Robin Labadie

    (@robin-labadie)

    Thanks for the try.
    So now it works almost as intended for the current domain.
    https://newdomain.org and https://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

    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.