John Davidson

Why doesn't my .htaccess file redirect to https? How to fix?

0 comments
Message:


Oh Jesus, I've tried this a million times, a million different ways using Stackoverflow, using blogs, my web host even did it at one point, to no success, or maybe my fiddling with caching broke it.


I want to redirect all HTTP:// traffic to https, it's detering folk from buying.


So this is the content of the file, what needs to change???


AddType text/html .shtml
AddHandler server-parsed .shtml
Options Indexes FollowSymLinks Includes
AddHandler server-parsed .html .htm
<IfModule mod_deflate.c>
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
AddOutputFilter DEFLATE .shtml
</IfModule>

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.pottertour.co.uk/$1 [R,L]
</IfModule>

<IfModule mod_expires.c>
ExpiresActive On
ExpiresDefault "access plus 10 days"
ExpiresByType text/html "access plus 1 day"
ExpiresByType text/css "access plus 0 day"
ExpiresByType text/plain "access plus 1 month"
ExpiresByType image/gif "access plus 1 month"
ExpiresByType image/png "access plus 1 month"
ExpiresByType image/jpeg "access plus 1 month"
ExpiresByType image/jpg "access plus 1 month"
ExpiresByType image/webp "access plus 1 month"
ExpiresByType application/x-javascript "access plus 1 month"
ExpiresByType application/javascript "access plus 1 week"
ExpiresByType application/x-icon "access plus 1 year"
</IfModule>
# END EXPIRES

OK I tried removing the <IfModule mod_rewrite.c> wrappers as per MrWhite's comment, and it seemed to put the loading in a constant loop. So I returned it to what it was previously, but without the wrappers. As per below.


RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^pottertour.co.uk [NC]
RewriteRule ^(.*)$ https://www.pottertour.co.uk/$1 [L,R=301]


  • It's now blocking the loading of my google fonts and styles.css.
    Really CRITICAL!

  • It also fails to redirect.


Solutions and explanations well appreciated.


OK well thanks to MrWhite I've had another go, the whole .htacess file now stands at this:


AddType text/html .shtml
AddHandler server-parsed .shtml
Options Indexes FollowSymLinks Includes
AddHandler server-parsed .html .htm
<IfModule mod_deflate.c>
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
AddOutputFilter DEFLATE .shtml
</IfModule>

<IfModule mod_expires.c>
ExpiresActive On
ExpiresDefault "access plus 10 days"
ExpiresByType text/html "access plus 1 day"
ExpiresByType text/css "access plus 10 day"
ExpiresByType text/plain "access plus 1 month"
ExpiresByType image/gif "access plus 1 month"
ExpiresByType image/png "access plus 1 month"
ExpiresByType image/jpeg "access plus 1 month"
ExpiresByType image/jpg "access plus 1 month"
ExpiresByType image/webp "access plus 1 month"
ExpiresByType application/x-javascript "access plus 1 month"
ExpiresByType application/javascript "access plus 1 week"
ExpiresByType application/x-icon "access plus 1 year"
</IfModule>
# END EXPIRES

RewriteEngine On
RewriteCond %{HTTP:X-Forwarded-Proto} =http
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R,L]

Note I've removed all references to a permanent redirect by omitting the R=301


I've set a canonical https:// URL on all pages anyway, so I think adding to .htaccess doesn't help much.


It's still not accessing my styles.css or downloading google fonts. Nor is the browser executing on page javascript accordions correctly (how bizarre it's embedded on the page!)


I've contacted 1&1 my web host and asked them to ensure the .htacess file is 'refreshed'... I'll go off and research Cloudfare.



My Answer:
are you asking this question?

Rate this post

3 of 5 based on 8498 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us