2017-11-11 239 views
0

我已经为站点添加了ssl,现在我想在htaccess中使用重定向。HTTP到HTTPS重定向

我有这样一个htaccess的:

# BEGIN WordPress 
<IfModule mod_rewrite.c> 
RewriteEngine On 
#RewriteCond %{HTTPS} !=on 
#RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R,QSA] 
RewriteBase/
RewriteRule ^index\.php$ - [L] 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule . /index.php [L] 
</IfModule> 

什么,在哪里我应该增加对重定向? 钍求助

回答

0

使用.htaccess文件下面的代码会自动重定向访问者到你的网站的HTTPS版本:

# BEGIN WordPress 
<IfModule mod_rewrite.c> 
RewriteEngine On 

RewriteCond %{HTTPS} !=on 
RewriteRule^https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] 

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

而我应该把这段代码粘贴到我的代码中? – Narkomax

+0

可以吗? '#BEGIN WordPress的 RewriteEngine叙述在 的RewriteCond%{HTTPS}关闭 重写规则^ $ HTTPS(*)://%{HTTP_HOST}%{REQUEST_URI} [L,R = 301] RewriteBase/ RewriteRule^index \ .php $ - [L] RewriteCond%{REQUEST_FILENAME}!-f RewriteCond%{REQUEST_FILENAME}!-d RewriteRule。 /index.php [L] ' – Narkomax

+0

@Narkomax,你需要在你的.htaccess文件中加入这个文件并把它放到你的项目根文件夹中。 – Sinha

-1

你应该这样.htaccess文件粘贴到你的项目的根目录。