.htaccess Generator
Build Apache .htaccess rules visually — toggle rules and see the output instantly.
Rules
REDIRECTS
Redirect HTTP to HTTPS
Force all traffic to use HTTPS
WWW to Non-WWW
Redirect www.example.com → example.com
Non-WWW to WWW
Redirect example.com → www.example.com
Custom URL Redirect (301)
Permanently redirect one URL to another
Force Trailing Slash
Redirect /page → /page/
Remove .html Extension
Serve /about.html as /about
ERROR PAGES
Custom 404 Error Page
Show a custom page for 404 Not Found errors
Custom 500 Error Page
Show a custom page for 500 Server errors
SECURITY
Prevent Directory Listing
Hide file listings when no index file exists
Protect .htaccess File
Block direct HTTP access to .htaccess
Block Bad Bots
Block common scrapers and bad crawlers
Password Protect Directory
Require HTTP Basic Auth to access this directory
Block IP Address
Deny access from a specific IP address
PERFORMANCE
Browser Caching
Set cache headers for static assets
Enable Gzip Compression
Compress text assets with mod_deflate
Generated .htaccess
.htaccess Generator — Apache Config Builder
The .htaccess file (hypertext access) is a directory-level configuration file for the Apache HTTP Server. It allows you to override server settings for a specific directory without needing access to the main server config (httpd.conf).
What can .htaccess do?
- URL Redirects: Send visitors and search engines from old URLs to new ones
- HTTPS enforcement: Redirect all HTTP traffic to HTTPS
- Access control: Block IP addresses, bad bots, or require passwords
- Performance: Enable browser caching and Gzip compression
- Error pages: Show custom pages for 404, 500, and other HTTP errors
- URL rewriting: Create clean URLs without extensions
Important Notes
- The
.htaccessfile must be placed in the directory it should affect mod_rewritemust be enabled on your Apache server for redirect rulesAllowOverride Allmust be set in your Apache config for .htaccess to work- Test your rules thoroughly — incorrect configurations can lock you out of your site
WWW vs Non-WWW
Choose one canonical form for your domain — either always use www or never use it. This prevents duplicate content issues with search engines. Most modern sites prefer the non-WWW form.