.htaccess Generator Online
Toggle common Apache rules and copy a ready-to-use .htaccess, generated entirely in your browser.
Your domains, redirect paths, and IP addresses are processed locally in your browser to build the .htaccess, and nothing is uploaded to a server.
Setting file permissions? Try the chmod Calculator.
About .htaccess Generator
This .htaccess generator builds a valid Apache configuration file from toggles, so you do not have to memorise mod_rewrite syntax. Switch on the rules you need and the output updates live: force HTTPS, canonicalise www or non-www, add custom 301 redirects, deny specific IP addresses, set custom 404 and 500 error pages, enable gzip compression, turn on browser caching with mod_expires, disable directory listing, set a default DirectoryIndex, and add basic security headers like X-Frame-Options and Referrer-Policy. Rewrite-based rules are wrapped in a single mod_rewrite block with one RewriteEngine On, and every section gets a comment header so the file stays readable. It is built for developers and site owners moving a site to HTTPS or wiring up an apache redirect. The whole thing runs in your browser, so your domains, paths, and IPs never leave your device.
Features
- Force HTTPS by redirecting every http:// request to https:// with a 301
- Canonicalise the host to www or non-www with a single radio switch
- Add unlimited custom 301 redirects from old paths to new URLs
- Block access by IP address or CIDR range using a RequireAll block
- Set custom 404 and 500 ErrorDocument pages
- Enable gzip/DEFLATE compression and mod_expires browser caching for static assets
- Disable directory listing, set a default DirectoryIndex, and add security headers
- Copy the result or download it as .htaccess with one click
How to use the .htaccess Generator
- Toggle on the sections you need, such as Force HTTPS or Browser caching.
- Fill in any inputs, like redirect from/to paths or IP addresses to block.
- Watch the .htaccess output build live in the panel on the right.
- Click Copy, or Download to save the file as .htaccess in your site root.
Example
Input
Force HTTPS: on
Force www / non-www: remove www
Redirect: /old-page -> https://example.com/new
Output
<IfModule mod_rewrite.c>
RewriteEngine On
# Redirect all HTTP requests to HTTPS
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# Force non-www (strip www)
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [L,R=301]
# Custom 301 redirects
RewriteRule ^old-page/?$ https://example.com/new [L,R=301]
</IfModule>
HTTPS, non-www, and a custom redirect share one mod_rewrite block.
Common errors & troubleshooting
- You get a 500 Internal Server Error after uploading the file. — A required module may be off. Force HTTPS, www, and redirects need mod_rewrite; caching needs mod_expires; headers need mod_headers. Enable them or remove that section.
- The HTTPS or www redirect loops endlessly. — Make sure only one canonical redirect is active and that your host or proxy is not also forcing the opposite direction; combine HTTPS and www into the single generated block.
- Your custom 301 redirect does not fire. — Enter the path that the visitor requests in the From field (for example /old-page) and a full destination URL in the To field; clear your browser cache, since 301s are cached aggressively.
- The blocked IP can still reach the site. — This output uses Apache 2.4 syntax (Require not ip). On Apache 2.2 you would use Deny from instead, so confirm your server version.
Frequently asked questions
- What is a .htaccess generator?
- It is an in-browser tool that turns simple toggles and inputs into a valid Apache .htaccess file, covering HTTPS redirects, www canonicalisation, 301 redirects, IP blocking, compression, caching, and security headers, ready to copy or download.
- How do I force HTTPS in .htaccess?
- Enable the Force HTTPS toggle. It adds a mod_rewrite rule that checks RewriteCond %{HTTPS} off and 301-redirects every request to the https:// version of the same URL.
- Where does the .htaccess file go?
- Place it in the document root of your site (or the specific directory it should affect), name it exactly .htaccess with the leading dot, and make sure AllowOverride is enabled for that directory in your Apache config.
- How do I set up a 301 redirect with this htaccess generator?
- Turn on Custom 301 redirects, enter the old request path in the From field and the new URL in the To field, and add as many rows as you need; each becomes a RewriteRule with the [L,R=301] flags.
- Does this work for Nginx too?
- No. .htaccess is an Apache feature. Nginx ignores it and uses server-block directives in nginx.conf instead, so this output is for Apache or LiteSpeed servers.
- Is my configuration sent anywhere when I generate it?
- No. The .htaccess generator runs entirely in your browser, so the domains, paths, and IP addresses you enter are processed locally and never leave your device.
Related tools
All ArrayKit tools