.htaccess redirect generator

Build Apache redirect rules for HTTPS, www, a moved domain, single pages, whole folders and trailing slashes. The output is tested on a real Apache server, and it redirects in one hop, not two.

Free · Runs in your browser · Updated 26 September 2026

.htaccess redirect generator

Site-wide rules

Redirect to HTTPS
The www address
Only needed for the www option and a domain move.
Everything on it goes to the same path on your domain.
Trailing slash

Page and folder redirects

  • Starts with /. Add ?id=5 to match a query string.
    A full URL, or a path starting with /.

.htaccess

# Page and folder redirects (mod_alias)
RedirectMatch 301 "^/old-page/?$" "https://example.com/new-page"

RewriteEngine On

# Canonical address (HTTPS) in a single redirect
RewriteCond %{HTTPS} off
RewriteRule ^ "https://%{HTTP_HOST}%{REQUEST_URI}" [R=301,L]
  • If your site sits behind Cloudflare, a load balancer or another proxy that handles HTTPS, tick “behind a proxy”, or the HTTPS rule can loop.
  • Put these lines above any existing rewrite rules (WordPress, for example, above “# BEGIN WordPress”), back up the old file, and check with curl -I.

Rules generated.

What you get

One directive for each job.

What each option generates
You chooseGenerated withNotes
Redirect one pageRedirectMatchAnchored pattern, accepts a trailing slash. Special characters in the path are escaped.
A folder and everything in itRedirectMatches whole path segments and keeps the rest of the path and the query.
A page that is gone for goodRedirect goneSends a 410. The URL needs no destination.
A URL with a query stringRewriteCond + RewriteRuleRedirect and RedirectMatch never see the query string.
HTTPS and/or wwwRewriteCond + RewriteRuleCombined into one rule so a visitor is redirected once.
Move an old domainRewriteCond + RewriteRuleKeeps the path and the query.
Trailing slashRewriteCond + RewriteRuleReal folders and real files are left alone.

Tested

Run on a real Apache server.

Reading the documentation is not enough for redirects, because a rule that is almost right returns a server error for every page on the site. Each rule type this tool generates was requested on a real Apache 2.4 server and the status code and Location header were checked: 39 checks in the last run on 26 September 2026, covering exact and folder redirects, 410, 308, percent-encoded paths, query strings, HTTPS with and without a proxy, www both ways, a moved domain and trailing slashes.

That does not make it a substitute for testing on yours. Hosting setups differ, and a control panel may add its own rules. Check after you save:

curl -sI http://example.com/old-page
HTTP/1.1 301 Moved Permanently
Location: https://example.com/new-page

Before you paste

Five things that catch people out.

  • Back up the existing file first, and put the new lines above any existing rewrite rules. In WordPress, that means above the “# BEGIN WordPress” block.
  • Apache needs mod_alias and mod_rewrite, and the folder must allow overrides (AllowOverride FileInfo or All). If it does not, rules are ignored or the site returns a 500 error.
  • Paths are case-sensitive on most servers: /Old-Page and /old-page are different URLs.
  • Redirect chains cost time and dilute signals. Point old URLs straight at the final address, not at another redirect.
  • A 301 can be cached by browsers for a long time. Test with 302 first, then switch to 301 when you are sure.

FAQ

Questions people ask first.

Should I use a 301 or a 302 redirect?
Use 301 (or 308) when the move is permanent, so search engines transfer the old address to the new one. Use 302 (or 307) when it is temporary. While you are testing, use 302: browsers can keep a 301 for a long time, and undoing a cached 301 is awkward.
Does .htaccess work on Nginx?
No. .htaccess is an Apache feature (and works on servers that copy its behaviour, such as LiteSpeed). Nginx and IIS use their own configuration. In Nginx, for example, a permanent redirect to HTTPS is written as return 301 https://$host$request_uri; in the server block.
Why did my redirect create a loop?
The usual cause is a proxy or CDN (Cloudflare, a load balancer) that handles HTTPS and talks to your server over plain HTTP, so the server thinks every request is insecure and redirects forever. Tick “my site is behind a proxy or CDN” so the rule checks the X-Forwarded-Proto header instead.
What is the difference between “exact” and “include everything below it”?
Exact redirects only that URL, with or without a trailing slash. Including everything below it uses Apache’s Redirect directive, which also sends /old-page/anything to /new-page/anything. Use it to move a whole section.
Can I redirect a URL that has a query string?
Yes. Write the old URL with its query, for example /product.php?id=5. Apache’s Redirect ignores query strings, so the generator uses a mod_rewrite rule with a condition on the query and drops the old query from the new address.

From the team behind the tools

Building a product?

Daniotech builds web, mobile and real-time software for startups and teams. Tell us what you are making and who it is for.