2016-10-11 2 views
1

http를 https로, www를 www가 아닌 ​​곳으로 리디렉션하고 싶습니다.http to https, www가 아닌 ​​www 및 존경 url

케이스 :

http://example.com/my/url 
http://www.example.com/my/url 
https://example.com/my/url 
https://www.example.com/my/url 

결과

https://example.com/my/url 
https://example.com/my/url 
https://example.com/my/url 
https://example.com/my/url 

나의 현재 htaccess로 파일 :

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

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

문제 :

https://example.com/index.php으로 리디렉션됩니다.

나는 그것이 URL을 존중하고 싶다 https://example.com/my/url.

많은 질문을 발견했지만 아직 완전한 해결책을 찾지 못했습니다. 사실, 위의 htaccess 코드는 10 번 시도에서 아주 잘 작동 한 유일한 코드입니다.

답변

2

당신은 wwwhttp -> https을 제거하기 위해이 하나의 규칙을 사용할 수 있습니다
RewriteCond %{ENV:HTTPS} !on

그것은이다 : 당신은 너무 많은 리디렉션에 문제가있는 경우

RewriteEngine On 

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

# rest of rules go here .... 

이와 두 번째 라인을 교체하려고 이 규칙을 첫 번째 규칙 인으로 유지하고 테스트하기 전에 브라우저 캐시를 비우는 것이 중요합니다.

+1

한 가지 규칙에 모두 만족합니다. 나는 해결책이 다른 어떤 규칙들보다 우선한다고 생각한다. 감사! –

관련 문제