1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

[Help] htaccess issues with HTTPS

Discussion in 'Apache' started by Divvy, Mar 27, 2017.

  1. #1
    Hello guys,

    Can someone give me a little help with my htaccess file?
    I installed SSL in my site and now I'm having some problems adding a code to redirect from http:// to https://

    I think the code is fine:
    RewriteEngine On
    RewriteCond %{HTTPS} off
    RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
    Code (markup):
    The problem is that I'm using W3 Total Cache plugin and I think is causing conflict.
    I need someone to give a look to my .htaccess file.

    # BEGIN W3TC Page Cache core
    <IfModule mod_rewrite.c>
        RewriteEngine On
        RewriteBase /
        RewriteCond %{HTTPS} =on
        RewriteRule .* - [E=W3TC_SSL:_ssl]
        RewriteCond %{SERVER_PORT} =443
        RewriteRule .* - [E=W3TC_SSL:_ssl]
        RewriteCond %{HTTP_COOKIE} w3tc_preview [NC]
        RewriteRule .* - [E=W3TC_PREVIEW:_preview]
        RewriteCond %{REQUEST_METHOD} !=POST
        RewriteCond %{QUERY_STRING} =""
        RewriteCond %{HTTP_COOKIE} !(comment_author|wp\-postpass|w3tc_logged_out|wordpress_logged_in|wptouch_switch_toggle) [NC]
        RewriteCond "%{DOCUMENT_ROOT}/wp-content/cache/page_enhanced/%{HTTP_HOST}/%{REQUEST_URI}/_index%{ENV:W3TC_SSL}%{ENV:W3TC_PREVIEW}.html" -f
        RewriteRule .* "/wp-content/cache/page_enhanced/%{HTTP_HOST}/%{REQUEST_URI}/_index%{ENV:W3TC_SSL}%{ENV:W3TC_PREVIEW}.html" [L]
    </IfModule>
    # END W3TC Page Cache core
    
    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>
    # END WordPress
    
    ExpiresActive On
    <FilesMatch "\.(otf|ico|pdf|flv|woff)$">
    Header set Cache-Control "max-age=29030400, public"
    ExpiresDefault "access plus 1 years"
    Header unset Last-Modified
    Header unset ETag
    SetOutputFilter DEFLATE
    </FilesMatch>
    # 1 MONTHS
    <FilesMatch "\.(jpg|jpeg|png|gif|swf)$">
    Header set Cache-Control "max-age=2419200, public"
    ExpiresDefault "access plus 1 month"
    SetOutputFilter DEFLATE
    </FilesMatch>
    <FilesMatch "\.(xml|txt|css|js)$">
    Header set Cache-Control "max-age=604800, public"
    ExpiresDefault "access plus 1 week"
    SetOutputFilter DEFLATE
    </FilesMatch>
    # 30 MIN
    <FilesMatch "\.(html|htm|php)$">
    SetOutputFilter DEFLATE
    </FilesMatch>
    
    # compress text, html, javascript, css, xml:
    AddOutputFilterByType DEFLATE text/plain
    AddOutputFilterByType DEFLATE text/html
    AddOutputFilterByType DEFLATE text/xml
    AddOutputFilterByType DEFLATE text/css
    AddOutputFilterByType DEFLATE application/xml
    AddOutputFilterByType DEFLATE application/xhtml+xml
    AddOutputFilterByType DEFLATE application/rss+xml
    AddOutputFilterByType DEFLATE application/javascript
    AddOutputFilterByType DEFLATE application/x-javascript
    AddOutputFilterByType DEFLATE application/x-javascript
    AddOutputFilterByType DEFLATE application/font-woff
    
    # Or, compress certain file types by extension:
    <files *.html>
    SetOutputFilter DEFLATE
    </files>
    Code (markup):
    Whats the best place to add redirect code from http:// to https:// ?

    Please help :)
     
    Divvy, Mar 27, 2017 IP
  2. zacharooni

    zacharooni Well-Known Member

    Messages:
    346
    Likes Received:
    20
    Best Answers:
    4
    Trophy Points:
    120
    #2
    If it's WordPress, then you can set the 'siteurl' and 'home' rows to https:// in your WordPress database, via phpMyAdmin. It should then redirect by default to https, and change the base prefix, so assets not hardcoded should load over HTTPS.

    The RewriteRule looks fine, but test the aforementioned fix without it first, and add it back if needed. Anything else that displays mixed content errors after that is hardcoded.
     
    zacharooni, Apr 2, 2017 IP