.htaccess Generator
Generate Apache .htaccess configurations instantly. Force HTTPS, set browser caching, block directory listing, add custom redirects — no signup required.
How to Use
- Toggle each section on or off using the checkboxes.
- Configure options within each section (cache duration, www preference, etc.).
- The
.htaccessoutput updates in real time at the bottom. - Click Copy and paste into your
.htaccessfile.
What Each Section Does
- Force HTTPS: Adds a RewriteRule that issues a 301 redirect from any
http://request tohttps://. Requiresmod_rewrite. - WWW Redirect: Enforces a single canonical form of your domain — either always with
www.or always without it — preventing duplicate-content issues. - Directory Index: Sets the files Apache will serve when a directory URL is requested. Listing multiple files defines a fallback order.
- Browser Caching: Uses
mod_expiresto tell browsers how long to cache images, CSS/JS, and fonts. Reduces repeated requests and speeds up page loads. - Security: Disables directory listing (
Options -Indexes), blocks direct access to.htaccessand.env, and optionally adds XSS / clickjacking protection headers. - Custom Redirect: Creates a single-path redirect using the Apache
Redirectdirective. Choose 301 (permanent) or 302 (temporary).
FAQ
What is a .htaccess file?
.htaccess is a directory-level configuration file used by Apache web servers. It lets you override server settings per directory — including URL redirects, caching rules, access control, and security headers — without editing the main server config.
Will this work on Nginx or other servers?
.htaccess is Apache-specific. Nginx uses a different config syntax and does not read .htaccess files. If you are on Nginx, these rules need to be translated into nginx.conf directives.
Is it safe to deny access to .htaccess itself?
Yes, and it is recommended. Exposing .htaccess publicly can reveal server configuration details. The generated block uses Order/Deny directives to prevent the file from being served.
What is the difference between 301 and 302 redirects?
301 is a permanent redirect — browsers and search engines cache it and update links. 302 is a temporary redirect — clients check back each time. Use 301 for domain migrations or canonical URL changes, and 302 for short-term redirects.
How do I use the generated .htaccess file?
Copy the generated content, create (or edit) a file named .htaccess in your website's root directory, and paste it in. Upload or save the file, then test your site. Always keep a backup of any existing .htaccess before making changes.