Force HTTPS and Non-WWW with .htaccess for CloudFlare Users

后端 未结 1 750
我在风中等你
我在风中等你 2021-01-27 12:09

I am using CloudFlare and I want to force HTTPS and Non-WWW by using .htaccess

I know there are many examples online already, but for CloudFlare users, normal redirect m

1条回答
  •  说谎
    说谎 (楼主)
    2021-01-27 12:36

    With Cloudflare, you can use:

    RewriteEngine On
    # www -> https without www
    RewriteCond %{HTTP_HOST} ^www\.(.+) [NC]
    RewriteRule ^ https://%1%{REQUEST_URI} [NE,L,R=301]
    # http -> https
    # # With Cloudflare
    RewriteCond %{HTTP:CF-Visitor} '"scheme":"http"'
    # # Without Cloudflare
    # RewriteCond %{HTTPS} off
    RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [NE,L,R=301]
    

    0 讨论(0)
提交回复
热议问题