メインコンテンツにスキップ
.htaccess ジェネレーター

.htaccess ジェネレーター

必要なルール (HTTPS の強制、www または非 www リダイレクト、ディレクトリ一覧の無効化、ドットファイルのブロック、gzip とブラウザのキャッシュの有効化、カスタム エラー ページ、CORS の有効化) を切り替えて、すぐに使用できる Apache .htaccess を入手します。すぐにコピーまたはダウンロードできます。

100% クライアント側 - ブラウザからデータが流出することはありません

Force HTTPS

Redirect all HTTP traffic to HTTPS

Disable directory listing

Hide folder contents (Options -Indexes)

Block dotfiles

Deny access to .env, .git, etc.

Gzip compression

Compress text responses

Browser caching

Cache static assets

Custom error pages

404.html / 500.html

CORS: allow all origins

Access-Control-Allow-Origin: *

<IfModule mod_rewrite.c>
  RewriteEngine On
  # Force HTTPS
  RewriteCond %{HTTPS} off
  RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</IfModule>

# Disable directory listing
Options -Indexes

# Block access to dotfiles (.env, .git, etc.)
<FilesMatch "^\.">
  Require all denied
</FilesMatch>

# Gzip compression
<IfModule mod_deflate.c>
  AddOutputFilterByType DEFLATE text/html text/plain text/css text/javascript application/javascript application/json image/svg+xml
</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/svg+xml "access plus 1 year"
  ExpiresByType text/css "access plus 1 month"
  ExpiresByType application/javascript "access plus 1 month"
</IfModule>

Tip: place this file in your site's root. Test on staging first — a bad rule can take a site offline.

.htaccess ファイルの作成方法

リダイレクト、パフォーマンス、セキュリティのための Apache .htaccess ルールを生成します。

  1. 1

    オプションを選択してください

    HTTPS や gzip 圧縮を強制するなど、必要なルールを切り替えます。

  2. 2

    レビュー

    オプションを変更すると、.htaccess の更新が反映されます。

  3. 3

    展開する

    ファイルをサイトのルートにダウンロードします。最初にステージングでテストします。