.htaccess 생성기

충돌 검사와 함께 Apache .htaccess 리디렉션, 캐시, 보안 규칙 만들기

옵션

표준 URL
표준 호스트
끝 슬래시

/blog/index.html은 /blog/로 리디렉션됩니다.

사용자 지정 리디렉션
리디렉션: 0

아직 사용자 지정 리디렉션이 없습니다. 하나 추가하거나 일괄 붙여넣기를 사용하세요.

생성된 .htaccess

# Generated by the CodingTool.dev .htaccess Generator for Apache 2.4.
# Needs AllowOverride AuthConfig FileInfo Indexes Options (or All); Apache answers 500 for directives it does not allow.
# Place this file in the document root. Test on a staging site before going live.

# Disable directory listings.
Options -Indexes

# Deny access to .htaccess, .htpasswd and other .ht files.
<FilesMatch "^\.ht">
  Require all denied
</FilesMatch>

# Deny backup, dump and editor swap files such as .bak, .old, .sql, .swp and ~ copies.
<FilesMatch "(\.(bak|old|sql|swp)|~)$">
  Require all denied
</FilesMatch>

<IfModule mod_rewrite.c>
  RewriteEngine On

  # Block dotfiles and dot-folders such as .env and .git; keep /.well-known/ reachable.
  RewriteCond %{REQUEST_URI} !(^|/)\.well-known/
  RewriteRule (^|/)\. - [F]

  # Force HTTPS: redirect every HTTP request to the same host over HTTPS.
  RewriteCond %{HTTPS} !=on
  RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
</IfModule>

<IfModule mod_headers.c>
  # Basic security headers. Adjust Permissions-Policy if your site uses these features.
  Header always set X-Content-Type-Options "nosniff"
  Header always set Referrer-Policy "strict-origin-when-cross-origin"
  Header always set X-Frame-Options "SAMEORIGIN"
  Header always set Permissions-Policy "camera=(), microphone=(), geolocation=()"
</IfModule>

# Compress text responses. AddOutputFilterByType needs mod_filter in Apache 2.4.
<IfModule mod_deflate.c>
  <IfModule mod_filter.c>
    # Text and markup
    AddOutputFilterByType DEFLATE text/html text/plain text/css text/xml
    # Scripts and data
    AddOutputFilterByType DEFLATE text/javascript application/javascript application/json application/ld+json application/manifest+json
    # Feeds and XML
    AddOutputFilterByType DEFLATE application/xml application/rss+xml application/atom+xml
    # SVG and uncompressed fonts
    AddOutputFilterByType DEFLATE image/svg+xml font/ttf font/otf application/vnd.ms-fontobject
  </IfModule>
</IfModule>

# Browser caching (conservative): short lifetimes that are safe without versioned file names.
<IfModule mod_expires.c>
  ExpiresActive On
  # HTML and data: always revalidate
  ExpiresByType text/html "access plus 0 seconds"
  ExpiresByType application/json "access plus 0 seconds"
  ExpiresByType application/ld+json "access plus 0 seconds"
  ExpiresByType application/xml "access plus 0 seconds"
  ExpiresByType text/xml "access plus 0 seconds"
  # Feeds
  ExpiresByType application/rss+xml "access plus 1 hour"
  ExpiresByType application/atom+xml "access plus 1 hour"
  # CSS and JavaScript
  ExpiresByType text/css "access plus 1 week"
  ExpiresByType text/javascript "access plus 1 week"
  ExpiresByType application/javascript "access plus 1 week"
  # Web app manifest
  ExpiresByType application/manifest+json "access plus 1 week"
  # Images
  ExpiresByType image/avif "access plus 1 month"
  ExpiresByType image/gif "access plus 1 month"
  ExpiresByType image/jpeg "access plus 1 month"
  ExpiresByType image/png "access plus 1 month"
  ExpiresByType image/svg+xml "access plus 1 month"
  ExpiresByType image/webp "access plus 1 month"
  ExpiresByType image/x-icon "access plus 1 month"
  # Fonts
  ExpiresByType font/woff "access plus 1 month"
  ExpiresByType font/woff2 "access plus 1 month"
  ExpiresByType font/ttf "access plus 1 month"
  ExpiresByType font/otf "access plus 1 month"
  ExpiresByType application/vnd.ms-fontobject "access plus 1 month"
  # Audio and video
  ExpiresByType audio/mpeg "access plus 1 month"
  ExpiresByType audio/ogg "access plus 1 month"
  ExpiresByType video/mp4 "access plus 1 month"
  ExpiresByType video/webm "access plus 1 month"
</IfModule>

.htaccess는 Apache의 AllowOverride 설정이 이 지시어를 허용하는 곳에서만 동작합니다.

브라우저가 이름 앞의 점을 없애므로 htaccess.txt로 저장됩니다. 서버에서 .htaccess로 이름을 바꾸세요.

발견 사항

충돌이 없습니다
오류: 0 · 경고: 0 · 리디렉션: 0

참고 (3)

  • 참고: TLS를 종료하는 로드 밸런서나 CDN 뒤에서는 %{HTTPS}가 off라서 HTTPS 규칙이 반복될 수 있습니다. 먼저 호스팅 업체에 확인하세요.

  • 참고: AllowOverride AuthConfig, FileInfo, Indexes, Options(또는 All)이 필요합니다. 허용되지 않은 지시어가 있으면 Apache가 500을 반환합니다.

  • 참고: mod_rewrite, mod_headers, mod_deflate, mod_filter, mod_expires 모듈이 로드되지 않으면 해당 블록은 조용히 건너뜁니다.

이 파일의 구성

  • 서버 옵션
  • 파일 보호
  • 재작성 규칙
  • 응답 헤더
  • 압축
  • 브라우저 캐시

오류: 0 · 경고: 0 · 리디렉션: 0

생성되는 내용

이 생성기는 흔한 리디렉션, 성능, 보안 요구에 맞춰 Apache 2.4용 .htaccess 파일을 작성합니다. HTTPS 강제, 하나의 표준 호스트, 끝 슬래시와 index.html 정리, 사용자 지정 301/302/307/308 리디렉션, gzip 압축, Expires 캐시 프리셋, 디렉터리 목록과 점 파일 보호, 기본 보안 헤더, 선택적 HSTS, 사용자 지정 오류 페이지를 지원합니다. 각 구역에는 주석이 붙고 순서가 항상 같아서 변경 사항을 비교하기 쉽습니다.

충돌 검사

리디렉션은 파일에 쓰기 전에 원본 형식 오류, 안전하지 않거나 예상치 못한 대상 프로토콜, 중복, 자기 자신으로의 리디렉션, A에서 B로 갔다가 다시 A로 오는 순환, 불필요한 한 단계를 더하는 체인을 검사합니다. 순환하거나 실행되지 않을 규칙은 파일에서 빼고 발견 항목에 표시합니다. 표준 호스트와 끝 슬래시는 하나만 고르는 옵션이므로 www 추가와 www 제거처럼 모순되는 규칙을 함께 켤 수 없습니다.

중요한 Apache 세부 사항

모든 재작성 규칙은 하나의 IfModule mod_rewrite 블록에 들어가며 RewriteEngine On은 한 번만 나옵니다. HTTPS와 호스트 변경은 한 번의 리디렉션으로 처리하고, 끝 슬래시 규칙은 실제 파일과 폴더를 건너뛰며, 슬래시와 인덱스 리디렉션은 GET과 HEAD 요청에만 적용합니다. 접근 제어에는 Require all denied를 쓰고 오래된 Order와 Deny 문법은 쓰지 않습니다. 모듈에 의존하는 블록은 IfModule로 감싸므로 모듈이 없어도 사이트가 깨지지 않고 해당 블록만 건너뜁니다.

배포하기 전에

.htaccess는 서버의 AllowOverride 설정이 이 지시어를 허용할 때만 동작하며, 그렇지 않으면 Apache가 500을 반환합니다. 사용자 지정 리디렉션 경로가 문서 루트를 기준으로 하므로 파일은 문서 루트에 두세요. TLS를 종료하는 프록시나 CDN 뒤에서는 HTTPS 규칙이 원래 스킴을 알 수 없어 반복될 수 있습니다. HSTS는 HTTPS가 모든 곳에서 동작한 뒤 짧은 max-age로 시작하세요. 브라우저는 다운로드를 htaccess.txt로 저장하므로 서버에서 .htaccess로 이름을 바꾸세요. 모든 처리는 브라우저에서 이루어지며 아무것도 업로드되지 않습니다.

CodingTool이 공식 출시되었습니다

Launched on StartupBaseCodingTool.dev - Free, Fast & Easy Developer Tools in One Place | Product HuntCodingTool - Featured on Startup FameFazier badgeListed on Turbo0Featured on Twelve ToolsFeatured on Findly.toolsLaunchpadly Startup DirectoryCodingTool.dev — Featured on Smol Launch