Skip to content

Instantly share code, notes, and snippets.

@schlessera
Created May 8, 2015 19:12
Show Gist options
  • Select an option

  • Save schlessera/8d5091c021fb2495b1f6 to your computer and use it in GitHub Desktop.

Select an option

Save schlessera/8d5091c021fb2495b1f6 to your computer and use it in GitHub Desktop.

Revisions

  1. schlessera created this gist May 8, 2015.
    30 changes: 30 additions & 0 deletions .htaccess
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,30 @@
    # Redirect HTTP to HTTPS, for the main domain as well as all subdomains.
    #
    # Example:
    # http://domain.com/ => https://domain.com/
    # http://subdomain.domain.com/ => https://subdomain.domain.com/
    #
    # Make sure you replace "replacewithyourdomain" with your actual root domain!
    #
    # @author: Alain Schlesser <alain.schlesser@gmail.com>

    # The HTTP to HTTPS redirection code needs to go in front of the WordPress code.

    # Make sure RewriteEngine is on
    RewriteEngine On

    # First, redirect HTTP subdomains to HTTPS subdomains
    RewriteCond %{SERVER_PORT} 80
    RewriteCond %{HTTP_HOST} ^(.*)\.replacewithyourdomain\.com$
    RewriteRule ^(.*)$ https://%1.replacewithyourdomain.com/$1 [R=301,L]

    # Now, redirect HTTP main domain to HTTPS main domain
    RewriteCond %{SERVER_PORT} 80
    RewriteCond %{HTTP_HOST} ^replacewithyourdomain\.com$
    RewriteRule ^(.*)$ https://replacewithyourdomain.com/$1 [R=301,L]

    # BEGIN WordPress

    # [Here is your standard WordPress code, you should not modify this.]

    # END WordPress