.htaccess - 需要使用我当前的 htaccess 重定向到 HTTPS
问题描述
我想将 HTTP 和 www 重定向到https://example.com
.
我尝试使用:
# force HTTPS and www.
RewriteEngine On
RewriteCond %{HTTP_HOST} (?!^www\.)^(.+)$ [OR]
RewriteCond %{HTTPS} off
RewriteRule ^ https://www.%1%{REQUEST_URI} [R=301,L]
但结果只是https://www.
——域消失了!
我的当前.htaccess
:
<IfModule mod_rewrite.c>
# REWRITE ENGINE CONFIG
#ExpiresActive On
DirectoryIndex under_construction.html index.html index.php
#Header set Cache-Control "max-age=259200, public"
#ExpiresDefault "access plus 3 days"
#Header unset ETag
#FileETag None
# Expires header for static content
#<FilesMatch "\.(ico|jpg|jpeg|png|gif|js|css|swf|jgz|js.jgz)$">
#Header set Cache-Control "max-age=31536000, public"
#ExpiresDefault "access plus 11 months"
#</FilesMatch>
# Auth for non-public projects
#AuthName "ZEN 2.2 Login"
#AuthType Basic
#AuthUserFile /Applications/MAMP/htdocs/username/.htpasswd
#AuthUserFile F:/wamp/www/username/.htpasswd
#AuthGroupFile /dev/null
#require valid-user
# REWRITE CORE RULES RULES -- PLEASE DON'T MODIFY --
# THESE ARE THE MAIN REWRITES THAT MAKE THE ENTIRE WORLD SPIN
AddDefaultCharset UTF-8
# IF NO IMAGE FOUND
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} \.(gif|jpg|jpeg|png)$
RewriteRule .* resources/static/images/no_image.png [L]
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?page=$1&%{QUERY_STRING} [L,QSA]
RewriteRule ^robots.txt$ resources/static/robots.php [L]
# gZip minified js files
RewriteCond %{HTTP:Accept-Encoding} gzip
RewriteCond %{REQUEST_FILENAME}.jgz -f
RewriteRule (.*)\.js$ $1\.js.jgz [L]
AddType "text/javascript" .js.jgz
AddEncoding gzip .jgz
# gZip minified css files
RewriteCond %{HTTP:Accept-Encoding} gzip
RewriteCond %{REQUEST_FILENAME}.jgz -f
RewriteRule (.*)\.css$ $1\.css.jgz [L]
AddType "text/css" .css.jgz
AddEncoding gzip .jgz
</IfModule>
需要一些帮助将重定向到 HTTPS 和非 WWW 添加到当前.htaccess
文件。
从这里使用代码时的问题-> https://gist.github.com/vielhuber/f2c6bdd1ed9024023fe4
是重定向被破坏了,结果https://www.
只是,没有显示域名。
解决方案
尝试:
# force HTTPS and www.
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [OR]
RewriteCond %{HTTPS} !on
RewriteRule ^(.*)$ https://%1%{REQUEST_URI} [R=301,QSA,L]
HTTPS
使用 http 协议时,某些网络服务器不会创建标头。因此,如果未HTTPS
打开(关闭或为空),此条件为真。
推荐阅读
- javascript - 在 mobx 中实现“哑”输入组件
- mysql - 删除唯一 ia 索引列
- javascript - 函数“setSeconds( )”不适用于 p5.js Web 编辑器
- c# - 无法加载文件或程序集'CrystalDecisions.ReportAppServer.CommLayer,版本 = 13.0.2000.0,或其依赖项之一
- sql - 如何将 GENERATE_DATE_ARRAY 拆分为 Google Bigquery 中单行的日期以创建日期视图?
- typescript - 在打字稿中在客户端和服务器之间共享代码
- python - pandas 十分位在 DataFrame 行上排名
- c# - WPF - 使用动画在正方形中创建抛物线
- netsuite - 如何将自定义参数添加到套件的外部 URL。出于安全目的,如何通过身份验证访问套件的外部 url
- mongodb - 如何在mongodb中找到指定文档后面的文档?