
RewriteEngine를 활성화하는 방법은 Apache 웹 서버의 .htaccess 파일에 다음 코드를 추가하는 것입니다.
#hostingforum.kr
bash
RewriteEngine On
이 코드를 추가한 후, URL 리디렉션을 설정하기 위해 RewriteRule을 사용할 수 있습니다.
URL 리디렉션을 설정하는 예제는 다음과 같습니다.
#hostingforum.kr
bash
RewriteRule ^hello-world$ /hello-world/index.php [L]
이 코드는 /hello-world URL을 /hello-world/index.php로 리디렉션합니다.
경로 매핑을 설정하는 예제는 다음과 같습니다.
#hostingforum.kr
bash
RewriteRule ^hello-world/([0-9]+)$ /hello-world/index.php?id=$1 [L]
이 코드는 /hello-world/123 URL을 /hello-world/index.php?id=123로 리디렉션합니다.
RewriteRule의 옵션은 다음과 같습니다.
- ^ : 시작 문자열
- $ : 끝 문자열
- [L] : 리디렉션 후 더 이상의 처리를 하지 않음
- ([0-9]+) : 숫자를 매핑하는 정규 표현식
- $1 : 매핑된 숫자를 변수로 사용하는 방법
2025-03-20 00:29