Skip to content

htaccess forced HTTPS

    htaccess forced HTTPS

    Using .htaccess file to force HTTPS links in WordPresshttps

    Fix .htaccess to process website assets such as CSS and JavaScript under HTTPS

    This is the thing that got me when I was making the full transition to HTTPS for my blog.  After changing the site name, all my CSS and JavaScript assets were still coming in with the HTTP URL path rather than HTTPS.  This caused my site to appear broken in pretty much every browser.

    These site asset files can easily be corrected by fixing the rewrite rules in your .htaccess file found at the root of your WordPress application.

     

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    # BEGIN WordPress
    <IfModule mod_rewrite.c>
        RewriteEngine On
        RewriteCond %{SERVER_PORT} !^443$
        RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
        RewriteBase /
        RewriteRule ^index\.php$ – [L]
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteRule . /index.php [L]
    </IfModule>
    # END WordPress

    Notice the highlighted lines in the above code.  We’re saying that if the current port isn’t 443, then rewrite the URL to use HTTPS with a 301 redirect.  The rest of the above code should already exist in your WordPress .htaccess file. Usually, it will be found at the bottom of the file.

     

    https wordpress htaccess

     

    Well done and thank you to:

    https://www.thepolyglotdeveloper.com/2014/12/force-https-pages-wordpress-site/

    Even easier just past this at the very top first line of your .htaccess file:

    RewriteEngine On
    RewriteCond %{HTTPS} !=on
    RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]

    Join the conversation

    Your email address will not be published. Required fields are marked *