最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

htaccess - Globally force SSL on all pages

programmeradmin0浏览0评论

Right now my domain www.example is setup to force HTTPS and it works. The site also correctly links everything to HTTPS. (there are no occurences of HTTP in the database anywhere).

But if you are visiting a subpage, you can change the url to HTTP again, for example / and it will not enforce HTTPS.

I have this rule in my .htaccess in the root:

RewriteEngine On 
RewriteCond %{HTTP_HOST} ^example [NC]
RewriteCond %{SERVER_PORT} 80 
RewriteRule ^(.*)$ /$1 [R,L]

Any ideas what the cause of this is?

Right now my domain www.example is setup to force HTTPS and it works. The site also correctly links everything to HTTPS. (there are no occurences of HTTP in the database anywhere).

But if you are visiting a subpage, you can change the url to HTTP again, for example http://example/subpage/ and it will not enforce HTTPS.

I have this rule in my .htaccess in the root:

RewriteEngine On 
RewriteCond %{HTTP_HOST} ^example [NC]
RewriteCond %{SERVER_PORT} 80 
RewriteRule ^(.*)$ https://example/$1 [R,L]

Any ideas what the cause of this is?

Share Improve this question edited Apr 14, 2019 at 11:10 norman.lol 3,2413 gold badges30 silver badges35 bronze badges asked Jul 20, 2017 at 22:43 RizzahRizzah 333 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 2

To globally redirect all your pages to HTTPS add the following lines to your .htaccess:

# Globally force SSL.
RewriteCond %{HTTPS} off
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

This should be placed directly after RewriteEngine on if you have no previous rewrites.

Try this htaccess rule

RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
发布评论

评论列表(0)

  1. 暂无评论