.htaccess在地址栏中不包括https或http

时间:2017-09-28 18:27:48

标签: apache .htaccess mod-rewrite

如何强制domain.co.nz重定向到https://domain.co.nz

目前正在使用:

我目前正在使用以下.htaccess:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /sub-folder/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /sub-folder/index.php [L]
RewriteCond %{HTTPS} off 
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.*)$ [NC]
RewriteRule (.*) https://%1%{REQUEST_URI} [L,R=301]
RewriteRule ^([^.]+[^/])$ $1/ [L,R=301]
</IfModule> 

1 个答案:

答案 0 :(得分:0)

更改顺序:

<IfModule mod_rewrite.c>
RewriteEngine On

RewriteCond %{HTTPS} off 
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.*)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [NE,L,R=301]

RewriteRule ^([^.]+[^/])$ $1/ [L,R=301]

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

首先重定向!