SEO

Redirect (.htaccess) Generator

Build 301 and 302 redirects, HTTPS and www rules and domain moves as ready-to-paste Apache code. It runs in your browser; nothing is uploaded.

SITE-WIDE RULES
MOVE A WHOLE DOMAIN
YOUR .HTACCESS RULES

            

These rules are for Apache servers, which includes most cPanel hosting. Paste them near the top of your existing .htaccess, and keep a copy of the original first.

How to add the rules to your site

  1. Back up your current .htaccess. In cPanel, open File Manager, choose Settings and turn on Show Hidden Files, then download a copy of the file in your site's root folder (usually public_html).
  2. Paste the rules near the top of the file. If your site runs WordPress, put them above the # BEGIN WordPress block so they run first.
  3. Test. Open an old address in a private window, or check it with the HTTP Status Checker to see the status code and where it lands. Browsers cache 301 redirects, so test with a 302 first and switch when it works.

How to write the list

One redirect per line: the old address, then the new address. A full https:// new address is best, because it avoids a second redirect for http visitors. Anything after # at the start of a line is ignored.

/old-page/ https://example.com/new-page/
/pricing-2019/ https://example.com/pricing/ 302
/blog/* https://example.com/articles/*
/index.php?p=42 https://example.com/about/
/retired-page/ gone

The second line adds a type for that line only. The third moves a whole folder and keeps the page names. The fourth matches a specific query string, which the other lines cannot. The last answers 410 Gone. Old addresses match with or without a trailing slash, and the query string is passed on to the new address except in the query rule.

Redirect types

CodeMeaningUse it for
301Moved permanentlyRenamed or moved pages, site moves, https and www changes.
302Found (temporary)Short-term moves, sales pages, testing a new rule.
307Temporary, method keptTemporary moves where form posts must stay posts.
308Permanent, method keptPermanent moves where form posts must stay posts.
410GonePages removed on purpose with no replacement.

Everything here runs in your browser, and your addresses are never uploaded. The rules are standard Apache directives (RedirectMatch and mod_rewrite), so they work on Apache and on LiteSpeed, but not on Nginx or IIS.

Frequently asked

What is the difference between a 301 and a 302 redirect?

A 301 says the page has moved permanently, so search engines should move the old address's ranking to the new one and eventually drop the old address. A 302 says the move is temporary, so the old address stays indexed. 308 and 307 are the permanent and temporary versions that also keep the request method, which matters mostly for form posts and APIs.

Will a redirect keep my search rankings?

A permanent redirect tells search engines to treat the new address as the replacement, and ranking signals normally follow it. It works best when the new page is a close match for the old one. Sending many different old pages to one unrelated page, such as the homepage, is often treated as a soft 404 and gains little.

How does the * folder rule work?

An old address ending in /* matches everything inside that folder. A * in the new address is replaced by the rest of the old path, so /blog/* to https://example.com/articles/* sends /blog/my-post/ to /articles/my-post/. Without a * in the new address, the whole folder goes to one page.

Why is my redirect not working?

The usual causes are a server that is not Apache (Nginx ignores .htaccess), the file saved in the wrong folder, an earlier rule from a CMS or plugin that catches the address first, and the browser showing a cached 301. Test in a private window or with the HTTP Status Checker. If the whole site shows a 500 error after an edit, remove the last lines you added.

What is a redirect loop and how do I avoid it?

A loop happens when the new address sends the visitor back to the old one, directly or through other rules, and the browser stops with a too many redirects error. The tool flags the obvious cases, such as a page that redirects to itself. If an HTTPS rule loops behind Cloudflare or another proxy, check the proxy's SSL mode (use Full rather than Flexible), or delete the HTTPS lines and turn on Always use HTTPS in the proxy instead.

What does gone (410) do?

Writing gone instead of a new address answers with a 410 status, which says the page was removed on purpose and will not come back. Google treats it much like a 404, so it is mainly a clear signal for pages with no replacement.

How do I move a whole site to a new domain?

Open the Move a whole domain section, enter both domains and keep the page paths option on, then put the rules in the .htaccess of the old site. Every page then redirects to the same path on the new domain. This only works well if the new site keeps the same page addresses. Also use the Change of Address tool in Google Search Console.