301 Redirect Generator
Generate .htaccess 301 redirect rules in seconds.
Was this tool helpful?
Thanks for the feedback!
301 Redirect Generator writes the .htaccess lines that permanently send visitors and search engines from an old address on your site to a new one. You get the rule in two forms, a one-line Redirect directive and a mod_rewrite version, for Apache and LiteSpeed servers, which cover most shared hosting plans.
Filling in From path and To URL
From path is the old address without the domain, starting with a slash, such as /old-page.html. To URL is the full new address including https://. Both are required. For /old-page.html and https://example.com/new-page, Generate rules returns:
# 301 permanent redirect Redirect 301 /old-page.html https://example.com/new-page # Or with mod_rewrite: RewriteEngine On RewriteRule ^old-page\.html$ https://example.com/new-page [R=301,L]
In the second form the leading slash is dropped, because .htaccess rules see the path without it, and the dot is escaped as \. since a bare dot means "any character" in a regular expression.
Which of the two blocks to paste
Use one or the other, not both. They behave differently:
- Redirect 301 matches the path as a prefix.
Redirect 301 /blog https://example.com/newsalso sends/blog/monsoon-recipesto/news/monsoon-recipes, which is ideal when a whole folder moves. - RewriteRule with
^…$matches only that exact path./old-page/with a trailing slash won't match^old-page$; change the pattern to^old-page/?$to cover both.
If the file already contains RewriteEngine On, as WordPress's does, you don't need a second copy. Put your redirects above the # BEGIN WordPress block so they run before WordPress handles the request, and back up the file first, since one typo can make the whole site return a 500 error.
301 or 302?
A 301 tells browsers and search engines that the move is permanent. Google treats permanent redirects (301 and 308) as a strong signal that the new URL should replace the old one in search results, while temporary ones (302 and 307) suggest keeping the original. Use 301 when a page has been renamed, merged or moved to a new domain; use a 302 only for short-term situations such as a sold-out product page pointing to a category during a sale. Browsers cache 301s aggressively, so test in a private window, and fix a mistake quickly.
Keeping redirects healthy
- Avoid chains. If A already redirects to B and B now moves to C, update A to point straight at C rather than making visitors hop twice.
- Update your own links. Change internal links, your XML sitemap and the new page's canonical tag to use the new address instead of relying on the redirect.
- Keep them for a long time. Google's site-move guidance recommends leaving redirects in place for at least a year; there is little cost in keeping them longer.
- Query strings need extra rules. Neither line looks at the part after
?, so/product.php?id=42and/product.php?id=43can't be sent to different pages this way; that requires aRewriteCondon%{QUERY_STRING}.
On Nginx, which ignores .htaccess, the equivalent goes in the server block: location = /old-page.html { return 301 https://example.com/new-page; }. On WordPress, a redirect plugin is a reasonable alternative if you can't edit files.