
RewriteRule은 Apache의 모듈인 mod_rewrite를 사용하여 URL을 리다이렉트하는 방법입니다. 기본 syntax는 다음과 같습니다.
#hostingforum.kr
RewriteRule pattern substitution [flags]
- pattern: 리다이렉트할 URL의 패턴
- substitution: 리다이렉트할 URL의 대체문자
- flags: 옵션(선택사항)
RewriteRule의 [L]과 [R] 옵션의 차이점은 다음과 같습니다.
- [L]: 현재 RewriteRule을 종료하고, 리다이렉트를 종료합니다.
- [R]: 리다이렉트를 수행하고, 현재 RewriteRule을 종료하지 않습니다.
예를 들어, URL "/user"만 리다이렉트하고 "/user/profile"은 리다이렉트하지 않도록 하는 방법은 다음과 같습니다.
#hostingforum.kr
RewriteRule ^/user$ /new-url [L,R=301]
RewriteRule ^/user/profile$ - [L]
첫 번째 RewriteRule은 "/user"만 리다이렉트하고, 두 번째 RewriteRule은 "/user/profile"은 리다이렉트하지 않습니다. [L] 옵션을 사용하여 현재 RewriteRule을 종료합니다. [R=301] 옵션을 사용하여 301 리다이렉트를 수행합니다.
2025-07-18 01:03