2014-02-05 152 views
4

我想重定向所有非www到www - 如果请求是通过http它应该重定向到http://www.domain.com,如果请求是通过https然后直接到https://www.domain.com重定向所有非www到WWW http和https与.htaccess

我试图在我的.htaccess以下,但它的一切重定向到https

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

我已经使用这个代码和它的解决非常完美。请检查它是否正确。

RewriteEngine On 
RewriteBase/
#Redirect non-www to www 

RewriteCond %{HTTP_HOST} !^www\. 
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L] 

# Redirect to HTTPS 
RewriteCond %{HTTPS} off 
RewriteRule (.*) https://www.pnrstatusbuzz.in/%{REQUEST_URI} 

回答

6

您可以使用此规则为您第一条规则

RewriteCond %{HTTP_HOST} !^www\. 
RewriteCond %{HTTPS}s on(s)| 
RewriteRule^http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L] 
+1

谢谢!!传奇 – ryerye

+1

经过大量的试验和错误,这也为我工作。非常感谢! – Ivan

相关问题