Swelıty
Tools for everyone

Free Online .htaccess Generator

Build an Apache .htaccess file with https and www redirects, page redirects, error pages, compression, caching, hotlink protection and IP blocking.

Settings

Switch on what you need

Start from

https, compression, caching and basic protection. Presets only change the switches, so your redirects and lists stay.

Page redirects

Send an old path to a new address, for example /old-page to https://example.com/new-page.

.htaccess

22 directives · 6 options on

RewriteEngine On

# Send every visit to https
RewriteCond %{HTTPS} off
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

# Error pages
ErrorDocument 404 /404.html

# Do not list the files in a folder
Options -Indexes

# Hide files that start with a dot (.env, .git)
<FilesMatch "^\.">
  Require all denied
</FilesMatch>

# Compress text files
<IfModule mod_deflate.c>
  AddOutputFilterByType DEFLATE text/html text/plain text/css text/xml
  AddOutputFilterByType DEFLATE application/javascript application/json application/xml image/svg+xml
</IfModule>

# Let browsers keep static files for 30 days
<IfModule mod_expires.c>
  ExpiresActive On
  ExpiresByType image/jpeg "access plus 30 days"
  ExpiresByType image/png "access plus 30 days"
  ExpiresByType image/webp "access plus 30 days"
  ExpiresByType image/svg+xml "access plus 30 days"
  ExpiresByType text/css "access plus 30 days"
  ExpiresByType application/javascript "access plus 30 days"
</IfModule>

Save this as .htaccess in the root folder of your site, on Apache. Keep a copy of the old file first: a mistake in .htaccess can take a site offline until it is fixed.

How to use

  1. Open the Redirects, Speed, Security and Pages tabs and switch on what you need.

  2. Add page redirects as an old path and a new address, and choose permanent (301) or temporary (302).

  3. Read the file on the right. Warnings appear above it if something looks wrong, such as an IP address that is not valid.

  4. Copy the file or download .htaccess, and upload it to the root folder of your site. Keep a copy of your old file first.

Why use this tool

  • Https and www rules

    Force https, and choose whether to always use or to remove www, with permanent redirects.

  • Page redirects

    Any number of 301 or 302 redirects from an old path to a new address.

  • Speed

    Gzip compression and browser caching for a number of days that you choose.

  • Security

    Hide folder listings and dot files, add security headers, stop image hotlinking and block or allow IP addresses.

  • Error pages

    Send any 4xx or 5xx status to your own page.

  • Checked as you type

    Warnings explain missing slashes, bad status codes and invalid IP addresses.

About this tool

The .htaccess Generator builds an Apache .htaccess file from switches and short forms, so you do not have to remember the directives. Force https, add or remove www, add trailing slashes, set up 301 and 302 page redirects, point error codes at your own pages, turn on gzip compression and browser caching, hide folder listings and files that start with a dot, add security headers, stop other sites from showing your images, and block or allow IP addresses. The file is built as you change the settings, with a comment above each block, and can be copied or downloaded under its exact name. It is written for Apache 2.4, and for servers that read .htaccess files, such as LiteSpeed.

Frequently asked questions

In the root folder of your website, next to your home page. The file name starts with a dot and has no other name, so make sure your file manager shows hidden files.

It works on Apache and on servers that read Apache rules, such as LiteSpeed. Nginx and many static hosts ignore .htaccess and need the same rules in their own format.

Yes. A wrong rule can cause a server error for the whole site. Keep a copy of the old file, upload the new one, and load your site straight away to check it. Restore the copy if anything is wrong.

A 301 is permanent and tells search engines to move the page's ranking to the new address. A 302 is temporary and keeps the old address in place.

Rewrites, compression, caching and headers rely on mod_rewrite, mod_deflate, mod_expires and mod_headers. Most hosts enable them, and the rules for the last three are wrapped so they are skipped when the module is missing.