htaccess - Globally force SSL on all pages

Right now my domain www.example is setup to force HTTPS and it works. The site also correctly links everything to HTTPS.

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]

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745481688a4629584.html

相关推荐

  • htaccess - Globally force SSL on all pages

    Right now my domain www.example is setup to force HTTPS and it works. The site also correctly links everything to HTTPS.

    2小时前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信