spyc.ai

Free tool

.htaccess Redirect Generator

Write Apache 301 and 302 redirect rules, with presets for HTTPS, www and trailing slashes.

How it works

What is the .htaccess Redirect Generator?

The .htaccess Redirect Generator is a free tool that writes Apache redirect rules from a list of old paths and new URLs. Choose 301 or 302 for each row, pick the Redirect, RedirectMatch or RewriteRule directive, and add presets that force HTTPS, switch between www and non-www, or normalise the trailing slash. Copy the result into your .htaccess file.

How to use the .htaccess Redirect Generator

  1. Add a row for each redirect: the old path, the new URL and 301 or 302.
  2. Turn on any presets you need: force HTTPS, www handling, trailing slash.
  3. Choose the directive: Redirect, RedirectMatch or RewriteRule.
  4. Copy the rules into the .htaccess file in your site root and test one old URL.

What is an .htaccess redirect?

.htaccess is a per-directory configuration file read by the Apache web server. A redirect rule in it tells Apache to answer a request for one URL with a 301 or 302 status and the address of another URL. Browsers and crawlers then go to the new address.

It only works where Apache, or a compatible server such as LiteSpeed, reads the file and the host allows overrides. On nginx the file is ignored; use the Nginx Redirect Generator there.

Should I use Redirect, RedirectMatch or RewriteRule?

Redirect is the simplest, but it matches a path prefix. Redirect 301 /old /new also sends /old/page to /new/page, which is useful for moving a folder and surprising when you meant one page. RedirectMatch takes a regular expression, and the generator anchors it with ^ and $ so only the exact path matches.

RewriteRule belongs to mod_rewrite and is the one to use when the site already has rewrite rules, since mixing the two modules can run rules in an order you did not expect. The generator escapes regex characters in the path for you.

When should I use a 301 and when a 302?

Use 301 when the move is permanent: a renamed page, a merged article, a new domain. Search engines treat it as a strong signal to index the new URL in place of the old one. Use 302 when the old URL will come back, such as a seasonal page or a temporary campaign.

Browsers cache 301 responses, sometimes for a long time. Testing with a 302 first and switching to 301 once it works saves you from a wrong redirect stuck in visitors' browsers.

How do I force HTTPS or remove www in .htaccess?

Both use mod_rewrite. The HTTPS preset checks %{HTTPS} off and redirects to the same host and path on https://. The www presets test %{HTTP_HOST} and redirect to the bare domain or to the www version. The trailing slash presets add or remove the final slash and skip real files or directories.

If your site sits behind a proxy or CDN that terminates TLS, %{HTTPS} may always read off and cause a loop. In that case force HTTPS at the proxy instead, for example with the Cloudflare Rules Generator.

Why is my .htaccess redirect not working?

The usual causes: the file is not in the directory that serves the URL, the host has overrides disabled, the path has a typo or a missing leading slash, or an earlier rule already handled the request. Query strings are a common trap too. These directives match the path only, so the generator drops a query string from the old path and tells you.

For a large migration, build and check the whole mapping with the Redirect Map Generator first; it flags chains and loops before they go live.

Questions

Where does the .htaccess file go?
In the document root of the site, the folder that holds your home page. The file name starts with a dot and has no extension.
Do I need RewriteEngine On?
Only for RewriteRule lines and the presets. The generator adds RewriteEngine On once, at the top, whenever the output needs it.
Can I redirect to another domain?
Yes. Enter the full URL including https:// as the target. A target that starts with a slash stays on the same host.
How many redirects can .htaccess hold?
There is no fixed limit, but Apache reads the file on every request, so thousands of lines slow things down. For very large maps, use the main server config or a RewriteMap.
Is the .htaccess Redirect Generator free?
Yes, with a free spyc.ai account. It runs in your browser, so nothing you type or paste is sent to a server.

Technical SEO Tools

More in Technical SEO Tools

Opengraph Viewer

Paste a URL and see the card it produces when someone shares it — title, description, image.

View Opengraph

Open Graph Generator

Write the Open Graph tags, preview the card, copy the markup.

Generate Open Graph tags

Robots.txt Checker

Fetch any site's robots.txt and test one URL against it: allowed, or blocked by which rule.

View robots.txt

Ready when you are

Before your next buyer asks AI about you, ask AI about yourself

One check, four engines, about twenty seconds. We show you the answers before we ask for anything.