2015-12-31 35 views
1

我有麻烦让我的htaccess重定向网站都www和https ...我曾尝试添加片段,我已经发现在以前的帖子,但最好的,我可以让它做的只是正确重定向网页,而不是其他...htaccess部队万维网和https

以下是完整的htaccess的

order deny,allow 
deny from all 
allow from env=allowclient 
SetEnvIf X-Cluster-Client-Ip 192.88.134.3 allowclient 
SetEnvIf X-Cluster-Client-Ip 192.88.135.3 allowclient 
SetEnvIf X-Cluster-Client-Ip 185.93.228.3 allowclient 
SetEnvIf X-Cluster-Client-Ip 185.93.229.3 allowclient 
SetEnvIf X-Cluster-Client-Ip 185.93.230.3 allowclient 
SetEnvIf X-Cluster-Client-Ip 192.88.134.0/23 allowclient 
SetEnvIf X-Cluster-Client-Ip 185.93.228.0/22 allowclient 
SetEnvIf X-Cluster-Client-Ip 192.124.249.0/24 allowclient 
SetEnvIf X-Cluster-Client-Ip 199.223.236.179 allowclient 
SetEnvIf X-Cluster-Client-Ip 146.148.117.213 allowclient 
SetEnvIf X-Cluster-Client-Ip 23.251.134.134 allowclient 
SetEnvIf X-Cluster-Client-Ip 178.33.238.180 allowclient 
SetEnvIf X-Cluster-Client-Ip 142.4.217.0/24 allowclient 
SetEnvIf X-Cluster-Client-Ip 167.114.0.0/24 allowclient 
SetEnvIf X-Cluster-Client-Ip 192.99.17.0/24 allowclient 
SetEnvIf X-Cluster-Client-Ip 5.196.79.0/24 allowclient 
SetEnvIf X-Cluster-Client-Ip 130.211.0.0/16 allowclient 
SetEnvIf X-Cluster-Client-Ip 104.155.0.0/16 allowclient 

# BEGIN WordPress 
<IfModule mod_rewrite.c> 
RewriteEngine On 
RewriteBase/

RewriteRule ^index\.php$ - [L] 
RewriteRule ^static/lib/(.*) /wp-includes/$1?p_hide_my_wp=soloshotfirst [QSA,L] 
RewriteRule ^file/(.*) /wp-content/uploads/$1?p_hide_my_wp=soloshotfirst [QSA,L] 
RewriteRule ^static/ext/(.*) /wp-content/plugins/$1?p_hide_my_wp=soloshotfirst [QSA,L] 
RewriteRule ^static/(.*) /wp-content/themes/tc/$1?p_hide_my_wp=soloshotfirst [QSA,L] 
RewriteRule ^enfold/(.*) /wp-content/themes/enfold/$1?p_hide_my_wp=soloshotfirst [QSA,L] 
RewriteRule ^static_main/(.*) /wp-content/themes/enfold/$1?p_hide_my_wp=soloshotfirst [QSA,L] 
RewriteRule ^ajax /wp-admin/admin-ajax.php?p_hide_my_wp=soloshotfirst [QSA,L] 
RewriteRule ^wp-content/themes/tc/screenshot\.png|readme\.html|license\.txt|wp-content/debug\.log|wp-includes/$ /nothing_404_404?p_hide_my_wp=soloshotfirst [QSA,L] 
RewriteRule ^(((wp-content|wp-includes)/([A-Za-z0-9\-\_\/]*))|(wp-admin/(!network\/?)([A-Za-z0-9\-\_\/]+)))(\.txt|/)$ /nothing_404_404?p_hide_my_wp=soloshotfirst [QSA,L] 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule . /index.php [L] 

</IfModule> 

# END WordPress 

<FilesMatch "\.(ttf|otf|woff)$"> 
<IfModule mod_headers.c> 
Header set Access-Control-Allow-Origin "*" 
</IfModule> 
</FilesMatch> 
+0

不能发现任何尝试重定向到'www'hostname或使用'https'作为协议。 – arkascha

回答

1

试试这个。

RewriteCond %{HTTPS} off [OR] 
RewriteCond %{HTTP_HOST} !^www\. 
RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301] 
+0

不,首先重定向到https和www,并且仅在https之后。你避免2重定向(一个用于https,另一个用于www) – Croises

+0

如果www已经存在,我们不需要重定向它。 – Arsalan

+0

您不会使用www重定向,但是使用您的规则,您可以在不使用www的情况下重定向到https,并在使用www的https后重定向。与我一起您重定向与www到https ou没有,但只有一个重写。 – Croises

1

使用(RewriteBase /后):

RewriteCond %{HTTP_HOST} !^www\. [NC] 
RewriteRule^https://www.%{HTTP_HOST}%{REQUEST_URI} [NE,L,R=301] 
RewriteCond %{HTTPS} off 
RewriteRule^https://%{HTTP_HOST}%{REQUEST_URI} [NE,L,R=301] 

只有一个重定向带或不带WWW