.htaccess Redirect & Security Generator
Build Apache .htaccess configuration files with HTTPS enforcement, canonical domain redirects, Gzip compression, browser caching, and custom 301 rules.
What is .htaccess Redirect & Security Generator?
An .htaccess file is a per-directory Apache or LiteSpeed configuration file. It can redirect old URLs, force HTTPS, choose a canonical www version, set browser caching, and block directory listings. This generator creates readable Apache 2.4 rules for those common jobs, plus custom redirects. The five rule groups are redirects, HTTPS forcing, www or non-www canonicalization, caching headers, and blocking rules such as Options -Indexes. Back up your existing file and test on staging first because a syntax or module error can cause a 500 response.
Back up your current configuration and test generated rules on staging before applying them to a live site.
A beginner guide to .htaccess rules
An .htaccess file applies configuration within a directory on supported Apache hosting. The server must allow the relevant overrides and have the required modules enabled. Nginx and Cloudflare Pages use other configuration systems. Start with your domain name, select only rules you need, and review the output. Back up the existing file and test on staging: an invalid directive can produce a server error.
- Redirects: Custom 301 Redirects send visitors from an old path to a new destination after a permanent page move. This tool does not offer custom 302 redirects.
- HTTPS forcing: redirects plain HTTP requests to HTTPS. A working certificate and correct proxy configuration are still required; it does not install a certificate.
- WWW choice: sends requests to your selected www or non-www address so visitors use one consistent domain form.
- Browser caching: sets expiry instructions for static assets, reducing repeat downloads when the browser can reuse its local cache.
- Blocking: directory-listing protection hides file indexes, while the separate IP field restricts specified addresses. These settings do not replace application security or authentication.
How to Use the .htaccess Redirect & Security Generator
- 1Enter "Your Domain Name", enable "Force HTTPS (SSL)" when supported, and choose the "Canonical Domain" option.
- 2Toggle the compression, browser caching, directory-listing, and protection rules required by your host.
- 3Use "Custom 301 Redirects" to enter old source paths and destination URLs; temporary 302 redirects are not offered.
- 4Review the output, click "Copy Code", and test on staging after backing up your existing .htaccess file.
How It Works
Generates Apache 2.4 mod_rewrite and mod_headers directives with [L,R=301] execution flags to ensure permanent canonical redirection without redirect loops.
HTTPS Rewrite: RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301].htaccess Redirect & Security Generator Frequently Asked Questions
Related Developer Tools
Explore more free tools in this category
JSON Formatter & Validator
Format, beautify, validate, and minify JSON data with line numbers and exact syntax error diagnostics.
CSS Minifier & Beautifier
Minify CSS stylesheets to reduce file size or beautify minified styles with clean indentation.
HTML Minifier & Beautifier
Compress HTML documents by removing comments and whitespace, or format unreadable code into neat tags.
JS Minifier & Beautifier
Format unreadable JavaScript code with proper spacing or strip spaces and comments for fast loading.