
RewriteRule의 기본 syntax는 다음과 같습니다.
RewriteRule pattern substitution [flags]
- pattern : 리다이렉트할 URL 패턴
- substitution : 리다이렉트할 URL
- flags : 옵션
RewriteRule을 사용하여 URL을 리다이렉트하는 방법은 다음과 같습니다.
1. 특정 URL을 리다이렉트하는 방법
http://example.com/path 를 http://example.com/newpath 로 리다이렉트하는 방법은 다음과 같습니다.
RewriteRule ^path$ /newpath [R=301,L]
- ^path$ : /path URL을 매칭
- /newpath : 리다이렉트할 URL
- R=301 : 리다이렉트할 때 HTTP 상태 코드 301을 사용
- L : RewriteRule이 끝났을 때 종료
2. URL에 매개변수를 포함한 리다이렉트
http://example.com/path?a=1&b=2 를 http://example.com/newpath?a=1&b=2 로 리다이렉트하는 방법은 다음과 같습니다.
RewriteRule ^path$ /newpath [QSA,R=301,L]
- QSA : URL에 매개변수를 포함한 리다이렉트를 허용
3. URL에 매개변수가 없는 리다이렉트
http://example.com/path?a=1&b=2 를 http://example.com/newpath 로 리다이렉트하는 방법은 다음과 같습니다.
RewriteRule ^path$ /newpath [R=301,L]
- 매개변수가 없기 때문에 QSA 옵션을 사용하지 않습니다.
4. URL에 매개변수만 리다이렉트
http://example.com/path?a=1&b=2 를 http://example.com/newpath?a=1&b=2 로 리다이렉트하는 방법은 다음과 같습니다.
RewriteRule ^path$ /newpath [QSA,R=301,L]
- 매개변수만 리다이렉트하기 때문에 QSA 옵션을 사용합니다.
2025-07-30 09:01