Which kind of redirect should you use?
Use a permanent server-side redirect when a URL has moved for good. It sends a 301 or 308 status before any page loads, and Google treats it as a strong signal that the new URL should replace the old one in results. This generator writes that rule for Apache, plus meta refresh and JavaScript fallbacks for hosts where you can't touch server config.
Google's redirects and Google Search page sets the order of preference: server-side first, then meta refresh, then JavaScript, and only if nothing else is possible, a plain link telling people the page moved.
The three snippets it writes
Enter a destination URL, pick a method, and click Generate. For https://example.com/pricing:
Apache .htaccess produces a mod_alias Redirect line with a placeholder source path. Above it, the output adds the comment line # Replace /old-path with the path you are redirecting from. as a reminder, followed by the rule itself:
Redirect 301 /old-path https://example.com/pricing
HTML meta refresh produces a tag for the old page's <head>. The delay slider (0 to 30 seconds) sets the number before the semicolon:
<meta http-equiv="refresh" content="0;url=https://example.com/pricing">
JavaScript produces a script that swaps the current page for the destination:
<script>window.location.replace("https://example.com/pricing");</script>
The delay slider only affects the meta refresh; the JavaScript and .htaccess versions ignore it. In the meta version, &, <, > and " in the URL are converted to HTML entities, so a destination like https://example.com/new-page?ref=a&b=1 becomes …?ref=a&b=1 inside the attribute, which browsers decode back correctly. The JavaScript version wraps the URL as a quoted JavaScript string and writes any < as \u003c, so a URL containing </script> can't close the script tag early; the browser still sees the original character. The .htaccess version percent-encodes any character that isn't allowed in a URL, so https://example.com/my page becomes https://example.com/my%20page and spaces, quotes or non-ASCII letters can't split the directive into extra arguments. Existing %XX escapes are left alone, and the URL decoder turns an encoded target back into readable text if you want to double-check it. Because Apache's Redirect only accepts an absolute URL or a path on the same server, the .htaccess method shows an error unless the destination starts with a scheme such as https:// or with /.
Permanent or temporary: what the status codes mean
The .htaccess snippet always uses 301. That's right for most moves, but here is how the main codes differ under RFC 9110 and in Google's handling:
| Code | Meaning | May a browser switch POST to GET? | Google uses it as a canonical signal? |
|---|---|---|---|
| 301 Moved Permanently | Moved for good | Yes, for historical reasons | Yes |
| 308 Permanent Redirect | Moved for good | No, method must be kept | Yes |
| 302 Found | Temporarily elsewhere | Yes, for historical reasons | No |
| 307 Temporary Redirect | Temporarily elsewhere | No, method must be kept | No |
For ordinary page moves the method question doesn't matter, since search engines and visitors arrive with GET. It matters for form endpoints and APIs: if a POST endpoint moves, use 308 (or 307) so the request body isn't dropped. Apache's Redirect accepts other numeric 3xx codes in place of 301, as well as the keywords permanent, temp and seeother.
Installing the .htaccess rule
- Copy the output and replace
/old-pathwith the old URL's path (you can delete the comment line, or keep it; Apache ignores lines starting with#), without the domain. It must start with/and is case-sensitive. - Open (or create) the
.htaccessfile in the site's document root. The directive needs mod_alias, which is part of standard Apache builds, and anAllowOverridesetting that permits FileInfo directives. - Paste the line and save.
- Request the old URL and confirm you get a single 301 straight to the destination. The redirect checker shows every hop.
Mind the prefix matching described in the mod_alias documentation. Redirect 301 /blog https://example.com/articles also sends /blog/2024/post to https://example.com/articles/2024/post, because the remainder of the path is appended. It matches whole path segments, so /blogroll is left alone. When you need to rewrite only one exact URL, or change the structure of the remaining path, use RedirectMatch with an anchored regular expression.
Pitfalls that cost rankings or visitors
Chains. Google's site move guide advises redirecting straight to the final destination and keeping chains short. When you move a page twice, update the first redirect to point at the newest URL.
Removing redirects too soon. The same guide says to keep redirects for as long as possible, generally at least a year, and suggests keeping them indefinitely for users' sake.
Timed meta refreshes. A delay above 0 is read by Google as temporary, and W3C's accessibility technique F41 lists timed refreshes as a failure unless users can turn off or adjust the timing. Use a delay only for a deliberate "this page has moved" notice.
JavaScript-only redirects. location.replace() removes the old page from the tab's history, so the back button doesn't bounce people into a loop, which is why the tool uses it. But Google only sees the redirect if rendering succeeds, so treat it as the fallback of last resort.
After a redirect goes live, make sure the destination's own canonical tag points to itself with the canonical URL checker.
Last updated