在.htaccess文件上编辑代码以指向https

在.htaccess文件上编辑代码以指向https,.htaccess,.htaccess,关于.htaccess文件,我必须在htaccess代码上编辑什么才能始终指向https 我读过其他问答,但我的代码似乎比那些要大 我的网站在wordpress上 DirectoryIndex index.php # BEGIN W3TC Browser Cache <IfModule mod_deflate.c> <IfModule mod_headers.c> Header append Vary User-Agent env=!don

关于.htaccess文件,我必须在htaccess代码上编辑什么才能始终指向https

我读过其他问答,但我的代码似乎比那些要大

我的网站在wordpress上

   DirectoryIndex  index.php
# BEGIN W3TC Browser Cache
<IfModule mod_deflate.c>
    <IfModule mod_headers.c>
        Header append Vary User-Agent env=!dont-vary
    </IfModule>
        AddOutputFilterByType DEFLATE text/css text/x-component application/x-javascript application/javascript text/javascript text/x-js text/html text/richtext image/svg+xml text/plain text/xsd text/xsl text/xml image/x-icon application/json
    <IfModule mod_mime.c>
        # DEFLATE by extension
        AddOutputFilter DEFLATE js css htm html xml
    </IfModule>
</IfModule>
# END W3TC Browser Cache

# BEGIN W3TC Page Cache core
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteCond %{HTTP:Accept-Encoding} gzip
    RewriteRule .* - [E=W3TC_ENC:_gzip]
    RewriteCond %{HTTP_COOKIE} w3tc_preview [NC]
    RewriteRule .* - [E=W3TC_PREVIEW:_preview]
    RewriteCond %{REQUEST_METHOD} !=POST
    RewriteCond %{QUERY_STRING} =""
    RewriteCond %{REQUEST_URI} \/$
    RewriteCond %{HTTP_COOKIE} !(comment_author|wp\-postpass|w3tc_logged_out|wordpress_logged_in|wptouch_switch_toggle) [NC]
    RewriteCond "%{DOCUMENT_ROOT}/wp-content/cache/page_enhanced/%{HTTP_HOST}/%{REQUEST_URI}/_index%{ENV:W3TC_PREVIEW}.html%{ENV:W3TC_ENC}" -f
    RewriteRule .* "/wp-content/cache/page_enhanced/%{HTTP_HOST}/%{REQUEST_URI}/_index%{ENV:W3TC_PREVIEW}.html%{ENV:W3TC_ENC}" [L]
</IfModule>
# END W3TC Page Cache core
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress
DirectoryIndex.php
#开始W3TC浏览器缓存
标头附加变量用户代理env=!不要改变
AddOutputFilterByType DEFLATE text/css text/x-component应用程序/x-javascript应用程序/javascript text/javascript text/x-js text/html text/richtext image/svg+xml text/plain text/xsd text/xsl text/xml image/x-icon应用程序/json
#扩展放气
AddOutputFilter DEFLATE js css htm html xml
#结束W3TC浏览器缓存
#开始W3TC页缓存核心
重新启动发动机
重写基/
RewriteCond%{HTTP:Accept Encoding}gzip
重写规则。*-[E=W3TC\u ENC:\u gzip]
重写Cond%{HTTP_COOKIE}w3tc_预览[NC]
重写规则。*-[E=W3TC\u预览:\u预览]
重写cond%{REQUEST_METHOD}=邮递
RewriteCond%{QUERY_STRING}=“”
重写cond%{REQUEST_URI}\/$
重写cond%{HTTP_COOKIE}!(注释|作者| wp \-postpass | w3tc |注销| wordpress |登录| wptouch |开关|切换)[NC]
重写条件“%{DOCUMENT_ROOT}/wp content/cache/page_enhanced/%{HTTP_HOST}/%{REQUEST_URI}/{index%{ENV:W3TC_PREVIEW}.html%{ENV:W3TC_ENC}”-f
重写规则。*“/wp content/cache/page_enhanced/%{HTTP_HOST}/%{REQUEST_URI}/{index%{ENV:W3TC_PREVIEW}.html%{ENV:W3TC_ENC}”[L]
#结束W3TC页缓存核心
#开始WordPress
重新启动发动机
重写基/
重写规则^index\.php$-[L]
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
重写规则/index.php[L]
#结束WordPress

使用我的网站替换example.com/yourdomain.com

为.htaccess文件执行此操作的代码为:

RewriteEngine On 
RewriteCond %{HTTP_HOST} ^typrograms\.com [NC]
RewriteCond %{SERVER_PORT} 80 
RewriteRule ^(.*)$ https://www.typrograms.com/$1 [R,L]
只需查找与此类似的代码。如果看不到,请将其添加到发动机的正下方

请注意:首先确保您的网站支持HTTPS!否则就不行了

我认为代码应该放在页面的顶部。(至少在第一位以上)