如何使用当前的htaccess设置重定向到https我的域?

时间:2017-07-25 20:14:45

标签: .htaccess redirect

我对htaccess文件相当新,我目前的配置如下:

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /
  RewriteRule ^index\.php$ - [L]
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule . /index.php [L]
</IfModule>

现在,我发现如果您想重定向到https,则需要使用以下内容:

 RewriteEngine On
 RewriteCond %{HTTPS} !^on$
 RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [L,R]

我的问题是我应该把这些线放在哪里?我可以从当前配置中删除一些吗?我很高兴任何人都可以解释当前配置的作用,或者至少指向正确的方向。

1 个答案:

答案 0 :(得分:0)

通过在.htaccess

的最顶部添加此代码解决了我的问题
<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteCond %{SERVER_PORT} !^443$
  RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</IfModule>

这也让您通过https

提供静态内容(css,图片)