
RewriteCond 문법은 RewriteRule 문법과 함께 사용하여 조건을 지정할 때 사용됩니다.
예를 들어, 특정 도메인에서만 리다이렉트를 발생시키고 싶을 때 사용합니다.
예를 들어, www.example.com에서 example.com으로 리다이렉트를 시키고 싶다면, RewriteCond 문법을 사용하여 다음과 같이 작성할 수 있습니다.
#hostingforum.kr
bash
RewriteCond %{HTTP_HOST} ^www.example.com [NC]
RewriteRule ^$ http://example.com [R=301,L]
이 문법은 www.example.com에서 example.com으로 리다이렉트를 시키는 것처럼 보입니다.
하지만, 단순하게 www.example.com에서 example.com으로 리다이렉트를 시키는 문법은 다음과 같습니다.
#hostingforum.kr
bash
RewriteRule ^$ http://example.com [R=301,L]
이 두 문법이 다르다면, RewriteCond 문법은 특정 조건을 지정할 때 사용됩니다.
예를 들어, 특정 도메인이나 IP 주소에서만 리다이렉트를 발생시키고 싶을 때 사용합니다.
또한, RewriteCond 문법을 사용하여 RewriteRule 문법을 여러 번 지정할 수 있습니다.
예를 들어, www.example.com에서 example.com으로 리다이렉트하고, example.com에서 www.example2.com으로 리다이렉트하고 싶다면, 다음과 같이 작성할 수 있습니다.
#hostingforum.kr
bash
RewriteCond %{HTTP_HOST} ^www.example.com [NC]
RewriteRule ^$ http://example.com [R=301,L]
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule ^$ http://www.example2.com [R=301,L]
이러한 예시를 통해 RewriteCond 문법의 사용법을 이해할 수 있습니다.
2025-06-23 23:12