CloudFlare的灵活的SSL和重定向 [英] Cloudflare flexible SSL and redirects

查看:2145
本文介绍了CloudFlare的灵活的SSL和重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些非常恼人的问题,我的域名。

我有我的网站上CloudFlare的灵活的SSL,它使一个HTTPS调用,如果我输入我自己>< 当我试图迫使https通过一个的.htaccess 文件中使用我的网站上,我碰到一个个内服务器错误。

我希望所有的游客到我的网站总是被重定向到 https://www.example.com 即使他们键入的例子。 COM example.com/index.php 等+使用https上的整个网站。

我只是无法找到解决办法,所以我想栈。

上的CloudFlare我的DNS设置为A记录指向 domain.com 来一个IP 和CNAME记录,上面写着 www.domain.com domain.com

的别名

我没有添加对CloudFlare的ATM页的规则。

 < IfModule mod_setenvif.c>
    < IfModule mod_headers.c>
        <\(?CUR | GIF | ICO | JPE G | PNG | SVGZ |的WebP)$FilesMatch>
            SetEnvIf之后起源:IS_CORS
            标题设置访问控制 - 允许 - 起源*ENV = IS_CORS
        < / FilesMatch>
    < / IfModule>
< / IfModule>

< IfModule mod_headers.c>
    < FilesMatch\(EOT | OTF | TT [CF] | WOFF)$。>
        标题设置访问控制 - 允许 - 起源*
    < / FilesMatch>
< / IfModule>


选项​​-MultiViews


< IfModule mod_headers.c>
    头集合X-UA-Compatible的IE =边缘
    #`mod_headers`不能匹配基于所述内容类型,但是,这种
    #头应只发送HTML页面,而不是为其他资源
    < FilesMatch "\.(appcache|atom|crx|css|cur|eot|f4[abpv]|flv|gif|htc|ico|jpe?g|js|json(ld)?|m4[av]|manifest|map|mp4|oex|og[agv]|opus|otf|pdf|png|rdf|rss|safariextz|svgz?|swf|tt[cf]|vcf|vtt|webapp|web[mp]|woff|xml|xpi)$">
        头取消设置的X UA兼容
    < / FilesMatch>
< / IfModule>

< IfModule mod_mime.c>

  #音频
    将AddType音频/ MP4 M4A F4A F4B
    将AddType音频/ OGG OGA OGG巨著

  #数据交换
    将AddType应用/ JSON JSON地图
    将AddType应用/ LD + JSON jsonld

    将AddType应用/ JavaScript的JS

  # 视频
    将AddType视频/ MP4 F4V f4p M4V MP4
    将AddType视频/ OGG远洋船
    将AddType视频/ W​​EBM WEBM
    将AddType视频/ X-FLV FLV

  #网页字体
    将AddType应用/字体WOFF WOFF
    将AddType应用/ vnd.ms-fontobject EOT


    将AddType应用程序/ x-字体TTF TTC TTF
    将AddType字型/ OpenType字体OTF


    将AddType图像/ SVG + XML SVGZ
    AddEncoding GZIP SVGZ

  # 其他
    将AddType应用/八位字节流safariextz
    将AddType应用程序/ x-铬扩展CRX
    将AddType应用程序/ x-歌剧扩展OEX
    将AddType应用程序/ x-WEB-APP-清单+ JSON的web应用
    将AddType应用程序/ x-xpinstall XPI
    将AddType应用/ XML原子RDF RSS XML
    将AddType图像/的WebP的WebP
    将AddType图像/ X图标CUR
    将AddType文本/缓存清单appcache清单
    将AddType文本/ VTT VTT
    将AddType文本/ x分量HTC
    将AddType文本/ X-名片VCF

< / IfModule>

AddDefaultCharset UTF-8


< IfModule mod_mime.c>
    AddCharset UTF-8 .atom的.css .js文件.json .jsonld的.rss .vtt .webapp的.xml
< / IfModule>


#< IfModule mod_rewrite.c>
#选项+的FollowSymLinks
   #选项+ SymLinksIfOwnerMatch
#RewriteEngine叙述上
   #重定向/folder/index.php到/文件夹/
#的RewriteCond%{THE_REQUEST} ^ [AZ] {3,9} \ /([^ /] + /)*指数\ .PHP \ HTTP /
#重写规则^(([^ /] + /)*)指数\ .PHP $ http://www.domain.dk/$1 [R = 301,L]
#< / IfModule>


#< IfModule mod_rewrite.c>
#的RewriteCond%{} HTTPS!=上
#的RewriteCond%{HTTP_HOST} ^ WWW \。(。+)$ [NC]
#^重写规则的http://%1%{REQUEST_URI} [R = 301,L]
#< / IfModule>

#< IfModule mod_rewrite.c>
#的RewriteCond%{} HTTPS!=上
#的RewriteCond%{HTTP_HOST}!^ WWW \。 [NC]
#的RewriteCond%{} SERVER_ADDR!= 127.0.0.1
#的RewriteCond%{} SERVER_ADDR!= :: 1
#重写规则^ HTTP://www.% {HTTP_HOST}%{REQUEST_URI} [R = 301,L]
#< / IfModule>


< IfModule mod_autoindex.c>
    选项​​-Indexes
< / IfModule>

< IfModule mod_rewrite.c>
    的RewriteCond%{} SCRIPT_FILENAME -D [OR]
    的RewriteCond%{} SCRIPT_FILENAME -f
    重写规则(^ | /)\。 - [F]
< / IfModule>

< FilesMatch(^#*#| \(BAK |配置|测距| FLA |在[CI] |登录| PSD | SH | SQL |申银万国[OP])|〜。)$>

    #阿帕奇< 2.3
    <!IfModule mod_authz_core.c>
        订购允许,拒绝
        所有拒绝
        满足所有
    < / IfModule>

    #阿帕奇≥2.3
    < IfModule mod_authz_core.c>
        要求所有被拒绝
    < / IfModule>

< / FilesMatch>

< IfModule mod_headers.c>
     头集X-内容类型 - 选项nosniff
< / IfModule>

#< IfModule mod_rewrite.c>
#的RewriteCond%{} SERVER_PORT!^ 443
#重写规则^ HTTPS://www.domain.dk% {REQUEST_URI} [R = 301,L]
#< / IfModule>



< IfModule mod_deflate.c>

    #强制COM pression的错位头。
    < IfModule mod_setenvif.c>
        < IfModule mod_headers.c>
            SetEnvIfNoCase ^(接受-EncodXng | X-CEPT-编码| X {15} |〜{15} |  -  {15})$ ^((GZIP |?放气)\ S * \ S *)+ | [X〜 - ] {4,13} $ HAVE_Accept,编码
            RequestHeader追加接受编码的gzip,紧缩ENV = HAVE_Accept,编码
        < / IfModule>
    < / IfModule>

    #的COM preSS标有以下MIME类型之一,所有输出
    #(低于2.3.7版本的Apache,你就不需要启用`mod_filter`
    #并可以删除`< IfModule mod_filter.c>`和`< / IfModule>`线
    #如`AddOutputFilterByType`仍处于核心指令)。
    < IfModule mod_filter.c>
        AddOutputFilterByType DEFLATE应用程序/原子+ XML \
                                      应用程序/ JavaScript的\
                                      应用程序/ JSON \
                                      应用/ LD + JSON \
                                      应用程序/ RSS + XML \
                                      应用程序/ vnd.ms-fontobject \
                                      应用程序/ x-字体TTF \
                                      应用程序/ x-WEB-APP-清单+ JSON \
                                      是application / xhtml + xml的\
                                      应用程序/ XML \
                                      字体/ OpenType字体\
                                      图像/ SVG + XML \
                                      图片/ X-图标\
                                      文/ CSS \
                                      文/ HTML \
                                      纯文本/ \
                                      文/ x分量\
                                      文/ XML
    < / IfModule>

< / IfModule>


< IfModule mod_headers.c>
   页眉设置缓存控制无转换
< / IfModule>

< IfModule mod_headers.c>
    头取消设置的ETag
< / IfModule>

FileETag无

#< IfModule mod_expires.c>

#ExpiresActive在
#ExpiresByType图像/ JPG的访问权限1年
#ExpiresByType为image / jpeg的访问权限1年
#ExpiresByType图像/ GIF的访问权限1年
#ExpiresByType图像/ PNG的访问权限1年
#ExpiresByType文本/ CSS的访问权限1月
#ExpiresByType text / html的访问权限1月
#ExpiresByType应用程序/ PDF的访问权限1月
#ExpiresByType文/ X-的javascript访问权限1月
#ExpiresByType应用程序/ x-冲击波闪光的访问权限1月
#ExpiresByType图像/ X-图标的访问权限1年
#ExpiresDefault访问权限1月

#< / IfModule>
 

解决方案

请尝试以下重写规则:

 < IfModule mod_rewrite.c>
 的RewriteCond%{} HTTPS的
 重写规则^ $ HTTPS(*)://%{HTTP_HOST}%{REQUEST_URI} [L,R = 301]
 的RewriteCond%{HTTP_HOST}!^ WWW \。
 重写规则^ $ HTTPS(*)://www.% {HTTP_HOST}%{REQUEST_URI} [L,R = 301]
< / IfModule>
 

另外,也请你有你在你的httpd.conf /的apache.conf文件中启用虚拟目录的SSL版本。

你是如何管理的域名?通过控制面板或者通过命令行?哪一类云耀斑您使用的是?你有没有在服务器上自己的SSL证书安装?

I'm having some really annoying problems with my domain.

I have Cloudflare flexible SSL on my site, and it makes a https call, IF I type it myself >< When I try to force https to be used on my site via a .htaccess file I get an internel server error.

I would like all visitors to my site to always be redirected to https://www.example.com even if they type example.com or example.com/index.php etc. + using https on the whole site.

I just can't find the solution to this, so I'm trying stack.

My DNS settings on Cloudflare is an A record that points domain.com to a IP and a CNAME record that says www.domain.com is an alias of domain.com

I have no page rules added on Cloudflare atm.

    <IfModule mod_setenvif.c>
    <IfModule mod_headers.c>
        <FilesMatch "\.(cur|gif|ico|jpe?g|png|svgz?|webp)$">
            SetEnvIf Origin ":" IS_CORS
            Header set Access-Control-Allow-Origin "*" env=IS_CORS
        </FilesMatch>
    </IfModule>
</IfModule>

<IfModule mod_headers.c>
    <FilesMatch "\.(eot|otf|tt[cf]|woff)$">
        Header set Access-Control-Allow-Origin "*"
    </FilesMatch>
</IfModule>


Options -MultiViews


<IfModule mod_headers.c>
    Header set X-UA-Compatible "IE=edge"
    # `mod_headers` cannot match based on the content-type, however, this
    # header should be send only for HTML pages and not for the other resources
    <FilesMatch "\.(appcache|atom|crx|css|cur|eot|f4[abpv]|flv|gif|htc|ico|jpe?g|js|json(ld)?|m4[av]|manifest|map|mp4|oex|og[agv]|opus|otf|pdf|png|rdf|rss|safariextz|svgz?|swf|tt[cf]|vcf|vtt|webapp|web[mp]|woff|xml|xpi)$">
        Header unset X-UA-Compatible
    </FilesMatch>
</IfModule>

<IfModule mod_mime.c>

  # Audio
    AddType audio/mp4                                   m4a f4a f4b
    AddType audio/ogg                                   oga ogg opus

  # Data interchange
    AddType application/json                            json map
    AddType application/ld+json                         jsonld

    AddType application/javascript                      js

  # Video
    AddType video/mp4                                   f4v f4p m4v mp4
    AddType video/ogg                                   ogv
    AddType video/webm                                  webm
    AddType video/x-flv                                 flv

  # Web fonts
    AddType application/font-woff                       woff
    AddType application/vnd.ms-fontobject               eot


    AddType application/x-font-ttf                      ttc ttf
    AddType font/opentype                               otf


    AddType     image/svg+xml                           svgz
    AddEncoding gzip                                    svgz

  # Other
    AddType application/octet-stream                    safariextz
    AddType application/x-chrome-extension              crx
    AddType application/x-opera-extension               oex
    AddType application/x-web-app-manifest+json         webapp
    AddType application/x-xpinstall                     xpi
    AddType application/xml                             atom rdf rss xml
    AddType image/webp                                  webp
    AddType image/x-icon                                cur
    AddType text/cache-manifest                         appcache manifest
    AddType text/vtt                                    vtt
    AddType text/x-component                            htc
    AddType text/x-vcard                                vcf

</IfModule>

AddDefaultCharset utf-8


<IfModule mod_mime.c>
    AddCharset utf-8 .atom .css .js .json .jsonld .rss .vtt .webapp .xml
</IfModule>


#<IfModule mod_rewrite.c>
#     Options +FollowSymlinks
   # Options +SymLinksIfOwnerMatch
#    RewriteEngine On
   # REDIRECT /folder/index.php to /folder/
#    RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*index\.php\ HTTP/
#    RewriteRule ^(([^/]+/)*)index\.php$ http://www.domain.dk/$1 [R=301,L]
#</IfModule>


#<IfModule mod_rewrite.c>
#    RewriteCond %{HTTPS} !=on
#    RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
#    RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L]
#</IfModule>

#<IfModule mod_rewrite.c>
#    RewriteCond %{HTTPS} !=on
#    RewriteCond %{HTTP_HOST} !^www\. [NC]
#    RewriteCond %{SERVER_ADDR} !=127.0.0.1
#    RewriteCond %{SERVER_ADDR} !=::1
#    RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
#</IfModule>


<IfModule mod_autoindex.c>
    Options -Indexes
</IfModule>

<IfModule mod_rewrite.c>
    RewriteCond %{SCRIPT_FILENAME} -d [OR]
    RewriteCond %{SCRIPT_FILENAME} -f
    RewriteRule "(^|/)\." - [F]
</IfModule>

<FilesMatch "(^#.*#|\.(bak|config|dist|fla|in[ci]|log|psd|sh|sql|sw[op])|~)$">

    # Apache < 2.3
    <IfModule !mod_authz_core.c>
        Order allow,deny
        Deny from all
        Satisfy All
    </IfModule>

    # Apache ≥ 2.3
    <IfModule mod_authz_core.c>
        Require all denied
    </IfModule>

</FilesMatch>

<IfModule mod_headers.c>
     Header set X-Content-Type-Options "nosniff"
</IfModule>

#<IfModule mod_rewrite.c>
#    RewriteCond %{SERVER_PORT} !^443
#    RewriteRule ^ https://www.domain.dk%{REQUEST_URI} [R=301,L]
#</IfModule>



<IfModule mod_deflate.c>

    # Force compression for mangled headers.
    <IfModule mod_setenvif.c>
        <IfModule mod_headers.c>
            SetEnvIfNoCase ^(Accept-EncodXng|X-cept-Encoding|X{15}|~{15}|-{15})$ ^((gzip|deflate)\s*,?\s*)+|[X~-]{4,13}$ HAVE_Accept-Encoding
            RequestHeader append Accept-Encoding "gzip,deflate" env=HAVE_Accept-Encoding
        </IfModule>
    </IfModule>

    # Compress all output labeled with one of the following MIME-types
    # (for Apache versions below 2.3.7, you don't need to enable `mod_filter`
    #  and can remove the `<IfModule mod_filter.c>` and `</IfModule>` lines
    #  as `AddOutputFilterByType` is still in the core directives).
    <IfModule mod_filter.c>
        AddOutputFilterByType DEFLATE application/atom+xml \
                                      application/javascript \
                                      application/json \
                                      application/ld+json \
                                      application/rss+xml \
                                      application/vnd.ms-fontobject \
                                      application/x-font-ttf \
                                      application/x-web-app-manifest+json \
                                      application/xhtml+xml \
                                      application/xml \
                                      font/opentype \
                                      image/svg+xml \
                                      image/x-icon \
                                      text/css \
                                      text/html \
                                      text/plain \
                                      text/x-component \
                                      text/xml
    </IfModule>

</IfModule>


<IfModule mod_headers.c>
   Header set Cache-Control "no-transform"
</IfModule>

<IfModule mod_headers.c>
    Header unset ETag
</IfModule>

FileETag None

#<IfModule mod_expires.c>

#ExpiresActive On
#ExpiresByType image/jpg "access 1 year"
#ExpiresByType image/jpeg "access 1 year"
#ExpiresByType image/gif "access 1 year"
#ExpiresByType image/png "access 1 year"
#ExpiresByType text/css "access 1 month"
#ExpiresByType text/html "access 1 month"
#ExpiresByType application/pdf "access 1 month"
#ExpiresByType text/x-javascript "access 1 month"
#ExpiresByType application/x-shockwave-flash "access 1 month"
#ExpiresByType image/x-icon "access 1 year"
#ExpiresDefault "access 1 month"

#</IfModule>

解决方案

Try the following rewrite rule:

<IfModule mod_rewrite.c>
 RewriteCond %{HTTPS} of
 RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
 RewriteCond %{HTTP_HOST} !^www\.
 RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</IfModule>

Also please check that you have an SSL version of your virtual directory enabled in your httpd.conf/apache.conf file.

How are you managing the domain name? Through a control panel or through command line? Which class of cloud flare are you using? Do you have your own SSL certificate installed on the server?

这篇关于CloudFlare的灵活的SSL和重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆