워드프레스 사이트를 설정하던 도중, 한글이 포함된 URL로 이동 시 오류가 발생했다. 이럴 때는 .htaccess에서 mod_rewrite를 설정하고 mod_url 인코딩 값을 변경해야 한다.
.htaccess란 “hypertext access”의 약자이며, 파일명 앞의 점은 숨김 파일이라는 의미이다. 웹 서버에서 브라우저 같은 클라이언트가 접근할 시 서비스를 어떤 식으로 제공할지 호스트 설정 파일을 통해 지정하는데, 이 때 서비스할 파일이 위치한 곳의 디렉터리 경로를 지정하거나 디렉터리의 접근 허용 여부를 지정한다.
Apache 웹 서버에서 .htaccess를 생성하고 설정하는 방법에 대하여 설명하겠다.
1. httpd.conf 설정
Apache 웹 서버의 httpd.conf를 수정해야 한다. 보통 기본 경로는 /etc/httpd/conf/ 내에 위치해 있다.
sudo vi /etc/httpd/conf/httpd.conf

설정할 경로의 디렉터리 영역에서 다음과 같이 설정한다.
Options Indexes FollowSymLinks AllowOverride All Require all granted Order allow,deny Allow from all

httpd.conf내에 .htaccess가 활성화되어있는지 확인한다. 주석 처리가 되어있으면 주석을 풀고 없으면 추가한다.
AccessFileName .htaccess

2. .htaccess 생성 및 설정
.htaccess를 설정할 경로에 숨김 파일로 생성하고 수정한다.
sudo touch .htaccess sudo vi .htaccess

.htaccess에 Apache 확장 모듈인 mod_rewrite로 전달받은 URL에 대한 규칙을 지정하고 mod_url로 파일명에 한글이 포함되어 있다면 UTF-8 형식이 아니더라도 EUC-KR 형식으로 작성된 같은 파일명을 불러올 수 있게 다음과 같이 지정한다.
<IfModule mod_rewrite.c> RewriteEngine On RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] RewriteBase / RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule> <IfModule mod_url.c> ServerEncoding UTF-8 ClientEncoding EUC-KR </IfModule>

모든 설정이 완료되었다면 웹 서버를 재부팅한다.
sudo systemctl restart httpd

한글이 포함된 URL로 이동이 잘 되는 것을 확인할 수 있다.

