2016-08-08 2 views
1

내 현재 .htaccess 파일 코드입니다..htacess에서 이중 301 리디렉션을 방지 하시겠습니까?

RewriteCond %{HTTP:X-Forwarded-Proto} !https 
    RewriteCond %{HTTPS} off 

    # First rewrite to HTTPS: 
    # Don't put www. here. If it is already there it will be included, if not 
    # the subsequent rule will catch it. 
    RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] 

    # Now, rewrite any request to the wrong domain to use www. 
    RewriteCond %{HTTP_HOST} !^www\. 
    RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301] 

참고 : - Remove double 301 redirect from my htacess? 을하지만이 코드에는 Redirect 없기 때문에이 여기에 적용되지 않습니다 나는이 질문을 확인했다.

답변

1

당신은 이중 301 리디렉션을 방지하기 위해이 규칙을 사용할 수 있습니다

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

테스트하기 전에 브라우저 캐시를 삭제해야합니다.

+1

예 @anubhava, 감사합니다. – Gaurav

관련 문제