How to create 301 redirects
- List each redirect on its own line: the old path, a space, then the new path or full URL. You can paste two columns straight from a spreadsheet.
- Choose where your site runs: Apache, Nginx, Netlify, Cloudflare Pages, Vercel, IIS, a PHP app, Express or Next.js.
- Pick the status code (301 for most moves) and copy the rules into the file named in the first comment.
A 301 is sent by the server in the HTTP response, before any page is rendered. That is what search engines need to move rankings to the new URL. An HTML <meta http-equiv="refresh"> tag or a JavaScript location.replace() is not a 301: the old page returns 200 first and search engines treat it as a weaker signal.
301, 302, 307 or 308?
| Code | Meaning | Use it when |
| 301 | Moved permanently | A page or site has moved for good (domain change, new URL structure, merged pages). Browsers cache it. |
| 308 | Permanent, method kept | Same as 301 but a POST stays a POST, e.g. for an API endpoint that moved. |
| 302 | Found (temporary) | A short-term move such as a sale page or maintenance; the old URL stays indexed. |
| 307 | Temporary, method kept | A temporary move for form posts or APIs. |
Example output
For /old-page /new-page with Apache selected:
Redirect 301 /old-page /new-page
and with Nginx:
location = /old-page {
return 301 /new-page$is_args$args;
}
Redirect best practices
- Redirect each old URL to its closest new equivalent, not everything to the home page; Google treats mass redirects to the home page as soft 404s.
- Avoid chains (A → B → C). Point every old URL straight at the final destination.
- Keep redirects in place for at least a year after a migration, and update internal links so visitors do not go through the redirect at all.
- Test with
curl -I https://example.com/old-page: the first line should read HTTP/1.1 301 or HTTP/2 301 with a location: header. The HTTP status code reference explains other responses.
FAQ
Where do I put the .htaccess rules?
In the .htaccess file in your site's document root, on Apache with AllowOverride enabled. Rules that match query strings need mod_rewrite, which the generator adds automatically. For more Apache settings, see the .htaccess generator.
Does a 301 pass SEO value?
Yes. Google has said 301 and 302 redirects both pass PageRank; the difference is which URL it keeps in the index. Use 301 or 308 for permanent moves so the new URL replaces the old one.
How do I redirect a whole domain?
On Apache, use RewriteCond %{HTTP_HOST} ^old\.com$ [NC] followed by RewriteRule ^(.*)$ https://new.com/$1 [R=301,L]; on Nginx, a server block for the old domain with return 301 https://new.com$request_uri;.