htaccess redirect generator
Choose the options, list old and new paths, then copy the rules into your .htaccess file.
Free · no signup Runs in your browser
How do I write a 301 redirect in .htaccess?
In an Apache .htaccess file, a permanent redirect is one line: Redirect 301 /old-page /new-page. List your old and new paths below, one pair per line, and the tool writes a line for each. It can also add the rules that force https, send visitors to either the www or the non-www version of your domain, set a custom 404 page and stop Apache listing the files in a folder.
Redirects that keep your rankings
A 301 status tells browsers and search engines that a page has moved permanently, so visitors are sent to the new address and the old address's ranking signals are passed on. Use it when you change a URL, merge two pages, move to https or settle on one version of your domain. Use it rather than a 302, which means 'temporary' and can leave the old URL in search results. Redirect a page to the page that replaces it, not to the home page; a redirect to an unrelated page is treated as a soft error.
The Apache Redirect directive matches the start of a path on whole path segments: Redirect 301 /blog /articles also sends /blog/my-post to /articles/my-post, but it does not match /blogging. For anything that depends on a condition, such as the host name or whether the connection is secure, the Apache documentation points to mod_rewrite, and that is what the www and https rules here use.
It runs in your browser. Nothing you enter is sent anywhere, and there is no sign-up.
Before you upload
Back up the existing .htaccess first. A typo can return a server error for the whole site. If your site sits behind a CDN or proxy that already handles https, the https rule can cause a redirect loop; in that case leave it off and set the redirect in the CDN. WordPress and other systems write their own rules into .htaccess, and their block should stay below yours. Check a redirect with a browser in a private window, since browsers cache 301s hard. Nginx servers do not read .htaccess, and need the equivalent rules in the server configuration.
When to use it
- Changing page URLs or restructuring a site
- Moving from http to https
- Choosing www or non-www
- Redirecting an old domain's pages to a new site
Mistakes it helps you avoid
- Using 302 where a permanent 301 is meant.
- Sending every old page to the home page.
- Redirect chains (A to B to C): redirect straight to the final URL.
- Replacing the existing .htaccess without a backup.
The formula
How the answer is worked out.
1. Preferred host (mod_rewrite): if the host is not the one you chose, 301 to https://preferred-host/path.2. HTTPS (mod_rewrite): if the connection is not secure, 301 to the same address with https.3. Each path redirect becomes: Redirect 301 /old-path /new-path-or-URL.4. Optional: ErrorDocument 404 /404.html and Options -Indexes.
The rules follow the Apache HTTP Server documentation for mod_alias and mod_rewrite. They are common patterns and work on most shared hosting, but your server's configuration decides (AllowOverride must permit them). The tool checks the form of what you enter; it cannot test your server.
Example: one moved page and https
You moved /services/roofing to /roofing and want https.
- Redirect lineRedirect 301 /services/roofing /roofing
- HTTPSRewriteCond %{HTTPS} off, then RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
Old address goes to the new one, and every http:// request goes to https://
Test in a private window.
Terms on this page
- 301 redirect
- A permanent redirect from one URL to another.
- .htaccess
- A per-folder configuration file read by Apache web servers.
Common questions
What is a 301 redirect?
A permanent redirect. It sends visitors and search engines to the new address and passes on ranking signals.
Does this work on Nginx?
No. Nginx does not read .htaccess; use the server configuration.
Why did my site break after uploading?
A syntax error or a setting the server does not allow. Restore your backup and add rules one at a time.
Should I redirect to the home page?
Only if nothing better exists. Redirect to the closest replacement page.
Is anything sent to a server?
No.
Is anything I enter sent to a server?
No. The calculation happens in your browser and nothing you type leaves your device.
Where these numbers come from
- Apache HTTP Server — mod_alias (Redirect) The Redirect directive, 'permanent' for a 301, and prefix matching on whole path segments.
- Apache HTTP Server — When not to use mod_rewrite Why simple redirects use Redirect and why mod_rewrite is for conditions such as the host name or HTTPS.
- Google Search Central — Redirects and Google Search Permanent versus temporary redirects and how Google treats them.
Last verified 2026-10-25 The method on this page is checked against the sources above at least once a year. Spotted something out of date? Tell us and we will fix it.
Related tools
Robots.txt generator
Build a robots.txt file with allow and disallow rules and your sitemap address, ready to copy.
Open toolSitemap generator
Paste your page addresses and get a valid sitemap.xml file to upload, with an optional last-modified date.
Open toolSlug generator
Turn a page title into a clean, lower-case, hyphenated URL slug, with accents removed and common words optionally dropped.
Open toolHreflang generator
Generate hreflang link tags, sitemap entries or HTTP headers for the language and country versions of a page, with checks for common mistakes.
Open toolKeyword density
Paste your text to see which words and phrases you repeat most and each phrase's share of the text.
Open toolMeta checker
Check the length of a page title and meta description and see a search result preview before you publish.
Open tool🔎 SEO tools
Small SEO jobs done in your browser: previews, checkers and generators. Nothing you enter is sent anywhere.
See all 12 tools in this section