2013-09-05 2 views
3

여기에서 이와 같은 몇 가지 질문을 보았습니다. 나는 이것을 알아낼 수 없다. 내가 www.example.org 또는 http://www.example.org에 갈 때마다.htaccess를 통해 http로 https를 리디렉션하지 마십시오.

# enable basic rewriting 

RewriteEngine on 

# enable symbolic links 
Options +FollowSymLinks 

# Primary Domain - Force the use of "https" 
RewriteCond %{HTTP_HOST} !^www\. 
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R=301,L] 

# Primary Domain - Force the use of "www" 
RewriteCond %{http_host} ^example.org [nc] 
RewriteRule ^(.*)$ https://www.example.org/$1 [r=301,nc] 

# Primary Domain - .com to .org 
RewriteCond %{HTTP_HOST} ^example.com$ [NC] 
RewriteRule ^(.*)$ https://www.example.org/$1 [R=301,L] 
RewriteCond %{HTTP_HOST} ^www.example.com$ [NC] 
RewriteRule ^(.*)$ https://www.example.org/$1 [R=301,L] 

# Primary Domain - .net to .org 
RewriteCond %{HTTP_HOST} ^example.net$ [NC] 
RewriteRule ^(.*)$ https://www.example.org/$1 [R=301,L] 
RewriteCond %{HTTP_HOST} ^www.example.net$ [NC] 
RewriteRule ^(.*)$ https://www.example.org/$1 [R=301,L] 

은 그래서 리디렉션되지 않습니다 : 여기 내 코드입니다. 이것이 나를 좌절시키는 것입니다. example.org 나 다른 리디렉션 중 하나를 선택하면 작동합니다. 내가 잘못 설정 한거야?

또한 "HTTP_HOST"라고 표시된 경우 그대로 두어도 되나요? 내가 그것을 내 http 호스트로 바꾸려면 어떻게합니까?

답변

1

Amie wwwhttps을 강제로 지정하려는 경우 www가 없는지 확인할 수 있습니다. 또는 https이 아니고On이 아닌지 확인하십시오. 따라서 어느 방향 으로든 리디렉션됩니다. 예.

# Primary Domain - Force the use of "https" and www 
RewriteCond %{HTTP_HOST} !^www\. [OR] 
RewriteCond %{HTTPS} !^on$ 
RewriteRule ^(.*)$ https://www.mydomain.org/$1 [R=301,L] 

mydomain.org를 내 도메인으로 교체하십시오.

그런 다음 htaccess 파일을 만들 수 있습니다. 마지막 두 규칙을 가져 와서 더 작은 htaccess 파일을 만들었습니다. 그것이 말하는

또한
# enable basic rewriting 
RewriteEngine on 

# enable symbolic links 
Options +FollowSymLinks 

# Primary Domain - Force the use of "https" and www 
RewriteCond %{HTTP_HOST} !^www\. [OR] 
RewriteCond %{HTTPS} !^on$ 
RewriteRule ^(.*)$ https://www.mydomain.org/$1 [R=301,L] 

# Primary Domain - .com to .org Or .net to .org 
RewriteCond %{HTTP_HOST} ^(www\.)?mydomain\.(net|com)$ [NC] 
RewriteRule ^(.*)$ https://www.mydomain.org/$1 [R=301,L] 

는 "HTTP_HOST"나는 그대로두고 있습니까? 나처럼 내 http 호스트로 바꾸시겠습니까?

%{HTTP_HOST}은 브라우저의 HTTP 헤더로 전송 된 호스트를 포함하는 변수입니다. 따라서 누군가 http://mydomain.org/somepage.php%{HTTP_HOST} 변수에 mydomain.org이 포함될 것을 요청하면 너는 그것을 바꾸지 않는다. 규칙과 같이 조건이나 조건을 일치시키는 데 사용할 수 있습니다. 희망이 귀하의 질문에 대한 답변.

관련 문제