DevOps

.htaccess Generator

Generate .htaccess rules for redirects, HTTPS enforcement, canonical hosts, caching and compression, with each directive explained.

Last reviewed by the Radiatus Cloud team

Redirect all traffic from HTTP to HTTPS automatically.

Want this automated for your stack?

We build CI/CD, Kubernetes & IaC pipelines that scale.

Talk to an engineer

What .htaccess is for, and when not to use it

An .htaccess file applies Apache configuration to the directory it sits in and everything below it. It exists for situations where you cannot edit the main server configuration, typically shared hosting. If you do have access to the vhost, put the directives there instead: Apache re-reads .htaccess on every single request and walks every parent directory looking for more, which is a measurable performance cost that vhost configuration does not carry.

Redirect status codes matter

A 301 is permanent and tells search engines to transfer the old URL's signals to the new one and update their index. A 302 is temporary and tells them to keep the original indexed. Using a 302 for a permanent move is one of the more common and more damaging SEO mistakes, because the new URL never accumulates the old one's authority. Use 301 for permanent moves and 302 only for genuinely temporary ones such as maintenance or A/B tests.

Pick one canonical host

A site reachable at both www and the bare domain, over both HTTP and HTTPS, has four URLs for every page. Redirect all of them to one canonical form in a single hop. Chained redirects, where HTTP goes to HTTPS and then non-www goes to www, waste crawl budget and add latency; combine the conditions into one rule that reaches the destination directly.

Rewrite rules are ordered and can loop

mod_rewrite processes rules top to bottom and, in a directory context, re-runs the whole set after a rewrite. Without a terminating condition a rule that rewrites into a path matching its own pattern loops until Apache stops it with a 500. Add RewriteCond %{REQUEST_FILENAME} !-f and !-d before a front-controller rule so real files and directories are served directly rather than rewritten.

Test before deploying

A syntax error in .htaccess takes the entire site down with a 500, immediately, for every visitor. There is no partial failure. Keep a known-good copy, change one thing at a time, and verify with curl -I that you get the status code you expect rather than trusting the browser, which caches 301s aggressively and will keep following a stale redirect long after you have fixed it.

Related tools

Frequently Asked Questions

Should I use 301 or 302?

301 for a permanent move: it transfers ranking signals and updates the index. 302 only for genuinely temporary situations. Using 302 for a permanent move means the new URL never inherits the old one's authority.

Why is my site returning a 500 error?

Almost certainly a syntax error in .htaccess, which takes the whole site down instantly. Restore your known-good copy, then reintroduce changes one at a time. Check the Apache error log for the exact line.

Is .htaccess slower than vhost configuration?

Yes. Apache re-reads it on every request and checks every parent directory for more. If you can edit the vhost, put the directives there and disable AllowOverride. The difference is measurable on busy sites.

Why does my rewrite rule loop?

In a directory context mod_rewrite re-runs the ruleset after each rewrite, so a rule whose output matches its own pattern loops until Apache returns a 500. Guard front-controller rules with RewriteCond checks for existing files and directories.

How do I redirect www and HTTPS in one hop?

Combine the conditions into a single rule that sends the request straight to the canonical scheme and host. Chaining separate HTTP-to-HTTPS and non-www-to-www rules costs an extra round trip and wastes crawl budget.

Privacy & Security

Generated locally in browser.

Data: None
Client-side-Side
Active
v1.0

About This Tool

This tool runs entirely in your browser. No data is sent to any server, ensuring complete privacy. Simply use the interface above to get started — no registration or login required.

Disclaimer: This tool is provided "as is" without warranty of any kind. Results are for educational and utility purposes.