1. 홈
  2. 개발자
  3. .htaccess 생성기

.htaccess 생성기

옵션을 고르면 Apache .htaccess 규칙을 만들어 주는 생성기입니다.

다른 형식·기능까지 한 번에 하려면 서버 설정 파일 생성기 →

내 브라우저에서 처리 · 업로드 없음

HTTPS · 주소 통일


주소 리다이렉트


오류 페이지


속도


보안 헤더


접근 제어

Options 지시어는 서버 설정에서 AllowOverride Options 를 허용해야 해요. 허용하지 않으면 500 오류가 나요.
Cloudflare 등 프록시 뒤인데 이 옵션을 끄면 무한 리다이렉트가 날 수 있어요. 그럴 땐 위의 프록시 항목을 켜세요.
Redirect(mod_alias)와 RewriteRule(mod_rewrite)을 섞으면 같은 주소에서 적용 순서가 헷갈릴 수 있어요. 결과를 꼭 확인하세요.
.htaccess
# .htaccess (Apache 2.4) # Redirects <IfModule mod_alias.c> Redirect 301 /old-page /new-page </IfModule> # Rewrite rules <IfModule mod_rewrite.c> RewriteEngine On # force HTTPS RewriteCond %{HTTPS} !=on RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] </IfModule> # Custom error pages ErrorDocument 404 /404.html # Disable directory listing Options -Indexes # Block hidden files such as .htaccess, .env, .git <FilesMatch "^\."> Require all denied </FilesMatch> # Compression <IfModule mod_deflate.c> AddOutputFilterByType DEFLATE text/html text/plain text/css text/xml text/javascript application/javascript application/json application/xml application/xhtml+xml application/rss+xml application/atom+xml image/svg+xml font/ttf font/otf application/vnd.ms-fontobject </IfModule> <IfModule mod_brotli.c> AddOutputFilterByType BROTLI_COMPRESS text/html text/plain text/css text/xml text/javascript application/javascript application/json application/xml application/xhtml+xml application/rss+xml application/atom+xml image/svg+xml font/ttf font/otf application/vnd.ms-fontobject </IfModule> # Browser caching <IfModule mod_expires.c> ExpiresActive On ExpiresByType image/jpeg "access plus 1 year" ExpiresByType image/png "access plus 1 year" ExpiresByType image/gif "access plus 1 year" ExpiresByType image/webp "access plus 1 year" ExpiresByType image/avif "access plus 1 year" ExpiresByType image/svg+xml "access plus 1 year" ExpiresByType image/x-icon "access plus 1 year" ExpiresByType text/css "access plus 1 month" ExpiresByType text/javascript "access plus 1 month" ExpiresByType application/javascript "access plus 1 month" ExpiresByType font/woff "access plus 1 year" ExpiresByType font/woff2 "access plus 1 year" ExpiresByType font/ttf "access plus 1 year" ExpiresByType font/otf "access plus 1 year" ExpiresByType text/html "access plus 0 seconds" </IfModule> # Security headers <IfModule mod_headers.c> Header always set X-Content-Type-Options "nosniff" Header always set X-Frame-Options "SAMEORIGIN" Header always set Referrer-Policy "strict-origin-when-cross-origin" Header always set Permissions-Policy "camera=(), microphone=(), geolocation=()" </IfModule>

이 파일은 Apache 용이에요. Nginx 는 .htaccess 를 읽지 않아요. 서버 설정에서 AllowOverride 가 막혀 있거나 해당 모듈(mod_rewrite, mod_headers, mod_expires, mod_deflate)이 꺼져 있으면 500 오류가 날 수 있으니 올리기 전에 기존 파일을 백업하세요.

사용 방법

  1. 필요한 옵션을 위에서부터 고릅니다. 기본값은 HTTPS 강제, 폴더 목록 숨김, 점(.) 파일 차단, 텍스트 압축, 캐시 설정입니다.
  2. 옛 주소를 새 주소로 보내려면 주소 리다이렉트에 경로를 적고, 종류(301 영구, 302 임시, 307·308 메서드 유지)를 고릅니다.
  3. 경고 상자를 읽고, 아래 .htaccess 결과를 복사하거나 파일로 내려받습니다.
  4. 웹사이트 최상위 폴더(보통 public_html)의 .htaccess에 올립니다. 이미 파일이 있다면 먼저 백업하세요.

옵션이 만드는 규칙

옵션 쓰이는 Apache 모듈 결과
HTTPS 강제 mod_rewrite RewriteCond %{HTTPS} !=on 뒤에 301 리다이렉트
www 통일 mod_rewrite www 있는/없는 주소 중 하나로 301
주소 리다이렉트 mod_alias Redirect 301 /옛경로 /새경로
압축 mod_deflate, mod_brotli HTML·CSS·JS·JSON·SVG 전송 크기 축소
브라우저 캐시 mod_expires 이미지·글꼴은 길게, HTML은 0초
보안 헤더 mod_headers nosniff, X-Frame-Options, Referrer-Policy, HSTS 등
핫링크 방지 mod_rewrite 다른 사이트가 내 이미지를 직접 불러가면 403
폴더 목록 숨김·점 파일 차단 핵심 기능, 접근 제어 Options -Indexes, <FilesMatch "^\.">

모든 모듈 규칙은 <IfModule>로 감싸 모듈이 없을 때 500 오류가 나지 않도록 했습니다. 다만 Options -Indexes처럼 <IfModule>로 감쌀 수 없는 지시어는 서버가 AllowOverride Options를 허용하지 않으면 오류가 납니다. 도구가 경고로 알려 줍니다.

실제 출력 예시

HTTPS 강제, www 통일, 리다이렉트 한 건, 404 페이지, 폴더 목록 숨김, 점 파일 차단만 고르면 다음처럼 나옵니다(압축·캐시·보안 헤더는 끈 상태).

# .htaccess (Apache 2.4)

# Redirects
<IfModule mod_alias.c>
  Redirect 301 /old-page /new-page
</IfModule>

# Rewrite rules
<IfModule mod_rewrite.c>
  RewriteEngine On
  # non-www to www
  RewriteCond %{HTTP_HOST} !^www\. [NC]
  RewriteCond %{HTTP_HOST} !^(localhost|[0-9.]+)(:[0-9]+)?$
  RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
  # force HTTPS
  RewriteCond %{HTTPS} !=on
  RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</IfModule>

# Custom error pages
ErrorDocument 404 /404.html

# Disable directory listing
Options -Indexes

# Block hidden files such as .htaccess, .env, .git
<FilesMatch "^\.">
  Require all denied
</FilesMatch>

www 통일과 HTTPS 강제를 함께 고르면 http://example.com이 한 번의 이동으로 https://www.example.com에 도착하도록 규칙 순서를 잡습니다. 리다이렉트가 두 번 이어지면 검색엔진과 방문자 모두 손해이기 때문입니다.

쓰기 전 알아둘 점

  • 프록시·CDN 뒤(Cloudflare 등)에서는 서버가 받는 요청이 늘 HTTP일 수 있어 HTTPS 강제가 무한 리다이렉트를 만듭니다. 이때는 프록시 옵션을 켜서 X-Forwarded-Proto 헤더로 판단하게 하세요.
  • HSTS는 한 번 켜면 브라우저가 max-age 동안 HTTPS만 쓰도록 기억합니다. includeSubDomains는 모든 서브도메인이 HTTPS를 지원할 때만 쓰세요. preload 목록 등록에는 max-age 1년 이상과 includeSubDomains가 필요합니다.
  • 인증과 IP 규칙을 함께 쓰면 둘 중 하나만 맞아도 통과합니다(OR). 둘 다 요구하려면 직접 <RequireAll>로 묶어야 합니다.
  • www 통일 규칙은 blog.example.com 같은 서브도메인 요청도 www.blog.example.com으로 보내려 합니다. 서브도메인을 같은 폴더에서 운영한다면 이 옵션을 쓰지 마세요.
  • Nginx에서는 .htaccess가 동작하지 않으므로 Nginx 설정 생성기를 쓰세요.

자주 묻는 질문

.htaccess 를 올렸더니 500 오류가 나요.

대부분 필요한 모듈이 꺼져 있거나 AllowOverride가 .htaccess 지시어를 막은 경우, 또는 줄 하나가 잘못된 경우입니다. 서버 오류 로그에 어느 줄이 문제인지 나옵니다. 올리기 전 백업해 둔 파일로 되돌려 보세요.

301 과 302 는 무엇이 다른가요?

301은 영구 이동이라 검색엔진이 새 주소로 평가를 옮기고, 302는 임시 이동이라 원래 주소를 유지합니다. 응답 코드의 의미는 HTTP 상태 코드에서 볼 수 있습니다.

이 파일을 어디에 올리나요?

도메인의 웹 루트(문서 루트) 폴더입니다. 하위 폴더의 .htaccess는 그 폴더 안에만 적용됩니다. 파일 이름이 점으로 시작해 숨김 파일로 보이니 FTP 프로그램의 숨김 파일 표시를 켜세요.

검색엔진 수집 규칙도 여기서 정하나요?

아닙니다. 수집 허용·차단은 robots.txt 생성기가 다룹니다.

방화벽 대역을 정리하려면 방화벽 규칙 생성기를, 비밀번호 보호용 .htpasswd 파일은 htpasswd 생성기를 함께 쓰세요. 입력한 내용은 브라우저 안에서만 처리되며 서버로 전송되지 않습니다.

필요한 도구가 없나요?

어떤 작업을 하고 싶은지 적어 주세요. 요청이 많은 도구부터 만듭니다.