Contents
see List작성일 2020. 12. 12.
Tomcat URL Rewrite 설정 가이드
Tomcat에서 www 붙이기/지우기, HTTP에서 HTTPS 리다이렉트, 301/302 응답 설정 방법입니다. UrlRewriteFilter를 사용합니다.
1. 의존성 추가
<!-- pom.xml -->
<dependency>
<groupId>org.tuckey</groupId>
<artifactId>urlrewritefilter</artifactId>
<version>4.0.4</version>
</dependency>
2. 필터 등록 (web.xml)
<filter>
<filter-name>UrlRewriteFilter</filter-name>
<filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>UrlRewriteFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
3. urlrewrite.xml 설정
<?xml version="1.0" encoding="UTF-8"?>
<urlrewrite>
<!-- www 붙이기 (301 영구 리다이렉트) -->
<rule>
<name>Add www</name>
<condition name="host" operator="notequal">^www.</condition>
<condition name="host">(.+)</condition>
<from>^(.*)$</from>
<to type="permanent-redirect">https://www.%1$1</to>
</rule>
<!-- www 지우기 (301 영구 리다이렉트) -->
<rule>
<name>Remove www</name>
<condition name="host">^www.(.+)</condition>
<from>^(.*)$</from>
<to type="permanent-redirect">https://%1$1</to>
</rule>
</urlrewrite>
4. HTTP → HTTPS 리다이렉트
<rule>
<name>Force HTTPS</name>
<condition name="scheme" operator="notequal">https</condition>
<from>^(.*)$</from>
<to type="permanent-redirect">https://%{server-name}$1</to>
</rule>
5. 301 vs 302 리다이렉트
| 구분 | 301 | 302 |
|---|---|---|
| 의미 | 영구 이동 | 임시 이동 |
| SEO | 권장 (링크 점수 전달) | 비권장 |
| 캐싱 | 브라우저가 캐시 | 매번 요청 |
| 설정 | type="permanent-redirect" | type="temporary-redirect" |
6. 경로 변경 규칙
<!-- 이전 URL을 새 URL로 -->
<rule>
<from>^/old-page$</from>
<to type="permanent-redirect">/new-page</to>
</rule>
<!-- 동적 경로 매핑 -->
<rule>
<from>^/blog/([0-9]+)$</from>
<to>/post.jsp?id=$1</to>
</rule>
<!-- 확장자 제거 -->
<rule>
<from>^/page/(.+)$</from>
<to>/$1.jsp</to>
</rule>
7. 조건 활용
<!-- 특정 IP만 접근 허용 -->
<rule>
<condition name="remote-addr" operator="notequal">192.168.1..+</condition>
<from>^/admin/.*$</from>
<to type="temporary-redirect">/403.html</to>
</rule>
<!-- 모바일 리다이렉트 -->
<rule>
<condition name="user-agent">.*(iPhone|Android).*</condition>
<from>^(.*)$</from>
<to type="temporary-redirect">https://m.example.com$1</to>
</rule>
주의사항
- 규칙 순서 중요 - 위에서 아래로 매칭
- 무한 루프 주의 - 조건 정확히 설정
- 프록시 환경에서는 X-Forwarded-Proto 헤더 확인
tool
| No | 작성일 | Title |
|---|---|---|
| 2204 | 2026. 02. 11. | GitHub Actions CI/CD 파이프라인 고급 패턴 |
| 2203 | 2026. 02. 11. | Docker Compose v2와 멀티스테이지 빌드 최적화 |
| 2202 | 2026. 02. 11. | Claude Code: AI 기반 터미널 개발 도구 완벽 활용법 |
| 2151 | 2026. 02. 11. | CI/CD 파이프라인 설계 베스트 프랙티스 |
| 2150 | 2026. 02. 11. | Kubernetes 모니터링: Prometheus + Grafana 스택 구축 |
| 2149 | 2026. 02. 11. | Git 고급 기법: Rebase, Cherry-pick, Bisect 활용 |
| 2148 | 2026. 02. 11. | Bun vs Node.js vs Deno: JavaScript 런타임 비교 2025 |
| 2147 | 2026. 02. 11. | Cursor AI IDE: AI 기반 코드 에디터 심층 리뷰 |
| 2146 | 2026. 02. 11. | VS Code 2025 필수 확장 프로그램과 설정 최적화 |
| 2145 | 2026. 02. 11. | Terraform으로 인프라 코드화(IaC) 시작하기 |