.htaccess Redirect Generator

Describe the redirects you need and get correctly ordered rewrite rules for Apache .htaccess, or the matching Nginx configuration. Loops and malformed lines are flagged as you type.

100% freeNo sign-upRuns in your browserWorks on mobile

Needed for www rules and to make targets absolute, which avoids redirect chains.

Site-wide rules

Separate the old and new address with a space. Write spaces inside a path as %20.

Move a whole domain (optional)

Every path on the old domain goes to the same path on the new one. Keep the old domain pointing at this server.

Generated rules

  

How to use the .htaccess Redirect Generator

  1. Choose Apache for an .htaccess file or Nginx for server configuration, and pick 301 for permanent moves or 302 for temporary ones.
  2. Enter your domain, then tick Force HTTPS and choose your www and trailing-slash preferences.
  3. List individual page redirects and folder moves, one per line, as the old path, a space and the new path or URL.
  4. Fill in the old and new domain if you are moving the whole site, and fix anything flagged in red.
  5. Copy or download the rules, back up your current configuration, and test a few old URLs after uploading.

Features

  • Page, folder, domain, HTTPS, www and trailing-slash redirects in one file
  • Rules ordered to avoid chains, with absolute targets on your preferred host
  • Query-string redirects such as product.php?id=7 handled correctly
  • Matching Nginx server blocks and location rules
  • Detects redirect loops and malformed lines as you type
  • Proxy-aware HTTPS rule for sites behind a CDN or load balancer

301 or 302?

A 301 redirect says a page has moved permanently. Browsers cache it, and search engines transfer the old URL’s ranking signals to the new one and eventually show only the new address. A 302 says the move is temporary, so search engines keep the original URL indexed. Use 301 for redesigns, renamed pages, HTTPS migrations and domain changes; use 302 for short-lived situations such as a seasonal landing page or maintenance. Because browsers cache 301s aggressively, test with 302 first if you are unsure, then switch.

How Apache reads these rules

The generated file uses mod_rewrite. Each RewriteRule has a pattern matched against the path without the leading slash, a target and flags: R=301 sends the redirect and L stops processing further rules. RewriteCond lines add conditions, such as checking the host name or whether the request used HTTPS. Apache keeps the original query string automatically; when a rule matches a specific query, the QSD flag drops it so it is not repeated on the new URL. The www rules use %{REQUEST_SCHEME}, which needs Apache 2.4 or later.

Worked example

The line /about-us.php /about/ with the domain example.com, Force HTTPS and “Never use www” becomes:

RewriteRule ^about-us\.php$ https://example.com/about/ [R=301,L]

The dot is escaped because in a regular expression an unescaped dot matches any character. The target is absolute, so a visitor arriving at http://www.example.com/about-us.php reaches the final page in a single hop instead of three.

Why order and chains matter

Each redirect adds a round trip, which slows visitors down, and long chains can stop search engines from following them to the end. The generator places domain moves first, then specific pages and folders with absolute targets on your preferred host, then the general HTTPS and www rules, and the trailing-slash rule last. Specific rules must come before general ones, or the general rule will fire first and the specific redirect will never be reached.

Nginx equivalents

Nginx does not read .htaccess files. Site-wide redirects belong in their own server blocks that answer for the old host names and return a redirect with $request_uri, which keeps the path and query string. Single pages use exact-match location = blocks, query-specific pages compare $request_uri, and folders use rewrite with the permanent or redirect flag. After editing, run nginx -t to check the syntax before reloading.

Mistakes to avoid

  • Redirect loops: moving /blog/ to /blog/new/ with a folder rule makes the new URL match the rule again. The tool warns you about this.
  • Redirecting everything to the home page: search engines may treat that as a soft 404. Send each old URL to its closest equivalent.
  • Breaking the file: a typo in .htaccess can return a 500 error for the whole site. Keep a backup and test right after uploading.
  • Forgetting internal links and sitemaps: update them to the new URLs so you do not rely on redirects forever. The XML Sitemap Generator helps rebuild the sitemap.

Check the status codes your server returns with the HTTP Status Codes reference.

Frequently asked questions

Where do I put the .htaccess file?

In the root folder of your website, usually public_html or www. If a file already exists, add the new rules near the top, after any existing RewriteEngine On line, rather than replacing CMS rules such as WordPress permalinks.

Why is the download called htaccess.txt?

Files whose names start with a dot are hidden on many systems and some browsers rename them. Rename the file to .htaccess after downloading, or copy the rules into your existing file.

Do 301 redirects lose SEO value?

Google has said that 301 and 302 redirects do not cause a loss of PageRank. What matters is sending each old URL to the most relevant new page and keeping chains short.

How long should I keep redirects in place?

For a domain or URL structure change, keep them for at least a year, and ideally for as long as old links to your site exist.

My site uses Nginx. Can I upload the .htaccess file?

No, Nginx ignores .htaccess files. Switch to the Nginx tab and add the generated blocks to your server configuration, then test and reload Nginx.

More seo & web tools

Other free tools you might need next.

View all 10