Htaccess Redirect
Generate 301 and 302 redirect code for your .htaccess file, to redirect URLs correctly. No signup. Ideal for setting up redirects on Apache servers the right way.
Share on Social Media:
This htaccess redirect generator creates 301 and 302 redirect code for your .htaccess file, directly in your browser. Enter your URLs and get the redirect code. No account, no install, so you can set up redirects the right way on any device in seconds.
How to Generate Redirect Code Step by Step
- Enter the URLs. Enter the URL you want to redirect from and the URL you want to redirect to, defining the redirect.
- Choose 301 or 302. Choose whether the redirect is a 301, permanent, or a 302, temporary, depending on your need.
- Generate the code. The tool generates the redirect code for your .htaccess file, based on your URLs and chosen redirect type.
- Add it to your .htaccess. Add the generated code to your site's .htaccess file, so the server applies the redirect.
- Test the redirect. Test that the redirect works as intended, so visiting the old URL correctly redirects to the new one.

What Redirects and .htaccess Are
A redirect sends visitors and search engines from one URL to another, so that visiting the old URL takes them to the new one. On Apache web servers, redirects are commonly set up in the .htaccess file, a configuration file, using redirect code. This generator creates that code for a 301 or 302 redirect, based on the URLs you provide, ready for your .htaccess.
Redirects are used when a URL changes or content moves, so that people and search engines reaching the old URL are sent to the new one, rather than hitting a dead end. This preserves access to content and, importantly for SEO, helps pass along the value of the old URL to the new one with a proper redirect. So redirects keep links working and content reachable when URLs change.
There are two main types: 301, a permanent redirect, and 302, a temporary one. A 301 indicates the move is permanent, which is appropriate when a URL has permanently changed and is important for SEO, as it signals the new URL is the permanent replacement. A 302 indicates a temporary move, appropriate when the change is temporary. So choosing the right type matters for signalling the nature of the redirect correctly.
Redirect code is used by web developers and site owners managing Apache sites: setting up redirects when URLs change, content moves, or old links need to point to new locations. Because redirects preserve access and SEO value when URLs change, and .htaccess is the common place to set them on Apache, a generator that creates correct 301 or 302 redirect code is a practical tool for managing redirects properly.
301 Versus 302 Redirects
| Type | Meaning | Use when |
|---|---|---|
| 301 | Permanent redirect | URL has permanently changed |
| 302 | Temporary redirect | The move is temporary |
| 301 and SEO | Passes value to new URL | Permanent changes |
| Applied in | .htaccess (Apache) | On Apache servers |
Who Uses Redirect Code

Pro Tips for Redirects
Common Redirect Mistakes to Avoid
Related Tools You May Need Next
For your site, our Broken Link Checker finds broken links, the Slug Generator helps with URLs, and other tools help you manage links.

Frequently Asked Questions
How do I generate redirect code?
Enter the URL you want to redirect from and the URL you want to redirect to, defining the redirect, choose whether it is a 301 permanent or 302 temporary redirect depending on your need, and the tool generates the redirect code for your .htaccess file based on your URLs and chosen type. Add the generated code to your site's .htaccess file, so the Apache server applies the redirect, then test that visiting the old URL correctly redirects to the new one. This lets you set up redirects the right way, sending visitors and search engines from an old URL to a new one, which preserves access when URLs change and, with a 301, passes SEO value to the new URL. So the generator creates correct 301 or 302 redirect code for your .htaccess, which you add and test, letting you manage URL changes and content moves properly on your Apache site.
What are redirects and .htaccess?
A redirect sends visitors and search engines from one URL to another, so that visiting the old URL takes them to the new one, rather than reaching a dead end. This is used when a URL changes or content moves, keeping links working and content reachable. On Apache web servers, redirects are commonly set up in the .htaccess file, which is a configuration file that lets you control aspects of how the server handles requests, including redirects, using redirect code. So .htaccess is where, on Apache, you place redirect code to tell the server to redirect one URL to another. This generator creates that redirect code, for a 301 or 302 redirect, based on the URLs you provide, ready to add to your .htaccess file. So a redirect is the mechanism sending one URL to another, and .htaccess is the Apache configuration file where such redirects are commonly set up, with the generated code implementing the redirect you want when added there.
What is the difference between 301 and 302 redirects?
The difference between 301 and 302 redirects is whether the move is permanent or temporary. A 301 redirect is permanent, indicating that the URL has permanently changed and the new URL is the permanent replacement. This is appropriate when a URL has permanently moved, and it is important for SEO, since a 301 signals to search engines that the new URL is the permanent location and helps pass the old URL's value to the new one. A 302 redirect is temporary, indicating that the move is not permanent, appropriate when you are temporarily redirecting a URL but intend to restore the original later. So the key difference is permanence: use a 301 for permanent changes, which is best for SEO on permanent moves, and a 302 for temporary redirects. Choosing the correct type matters, because it signals the nature of the move correctly to search engines and browsers. So use a 301 when a URL has permanently changed and a 302 when the redirect is only temporary, selecting based on whether the move is permanent or temporary.
When should I use a 301 redirect?
You should use a 301 redirect when a URL has permanently changed, meaning the content has permanently moved to a new URL and the old one should permanently lead to the new one. A 301 signals that the move is permanent and the new URL is the permanent replacement, which is important for SEO because it helps pass the value of the old URL to the new one, preserving search performance across the move. So for permanent changes, such as permanently moving a page to a new URL, restructuring URLs permanently, or consolidating content to a permanent new location, a 301 is the appropriate choice. Using a 301 for permanent moves ensures search engines understand the change is permanent and treat the new URL accordingly, passing on the old URL's value. So whenever a URL change is permanent and you want the old URL to permanently redirect to the new one while preserving SEO value, use a 301 redirect, reserving the 302 temporary redirect for cases where the move is only temporary and you intend to restore the original URL later.
How do I add the code to my .htaccess?
You add the generated redirect code to your Apache site's .htaccess file, which is the configuration file where such redirects are set on Apache servers. This involves placing the redirect code into the .htaccess file for your site, so that the server reads it and applies the redirect. The .htaccess file is typically located in your site's directory on the server, and you add the redirect code to it, following how .htaccess redirects are structured. Once the code is correctly in the .htaccess file, the Apache server applies the redirect, so visiting the old URL redirects to the new one. After adding the code, you should test that the redirect works, by visiting the old URL and confirming it correctly redirects to the new one. So the process is to take the generated redirect code and add it correctly to your site's .htaccess file, then test the redirect. Adding it correctly is important, since incorrect placement or code may mean the redirect does not work, so ensure the code is properly added to the .htaccess for the server to apply the redirect as intended.
Why test the redirect after setting it up?
You should test the redirect after setting it up to confirm it works as intended, since adding redirect code without testing risks the redirect not functioning correctly due to an error or incorrect setup. By testing, you visit the old URL and check that it correctly redirects to the new URL, verifying the redirect is working. This catches any problem, such as the code being added incorrectly, the wrong destination URL, or another issue, before you rely on the redirect. If you do not test, you might assume the redirect works when it actually does not, leaving the old URL not redirecting properly, which could mean visitors hitting a dead end or the SEO benefit not being achieved. So testing is an important final step: it confirms the redirect functions correctly, sending the old URL to the intended new one, giving you confidence it is set up right. So after adding the redirect code to your .htaccess, always test the redirect by visiting the old URL and confirming it leads to the correct new URL, ensuring the redirect works as you intended before depending on it.
What happens to SEO when I redirect?
When you set up a redirect, particularly a 301 permanent redirect, it helps preserve SEO value across the URL change. A 301 signals to search engines that the URL has permanently moved to the new one, and it helps pass the value of the old URL to the new URL, so the search performance associated with the old URL is largely carried over to the new one. This is important when you change or move URLs, because without a proper redirect, the old URL's value could be lost and visitors or search engines might reach a dead end. So using a 301 for permanent moves helps maintain your SEO by transferring value to the new URL. A 302 temporary redirect, by contrast, signals a temporary move and is used when you do not want to permanently transfer the URL, so it is used for temporary situations rather than permanent SEO transfers. So for preserving SEO on permanent URL changes, a 301 redirect is the appropriate choice, helping pass the old URL's value to the new one, whereas a 302 is for temporary moves. So redirects, especially 301s, are important for maintaining SEO when URLs change.
Is the htaccess redirect generator free?
Yes, it is completely free with no account and no usage limit. You can generate redirect code for as many redirects as you like, as often as you like, at no cost. It runs in your browser on any device, so there is nothing to download or install, and your redirect code is ready once generated from your URLs and chosen redirect type. Use it to create 301 permanent or 302 temporary redirect code for your Apache site's .htaccess file, setting up redirects the right way when URLs change or content moves. Remember to use a 301 for permanent changes, which is best for SEO, and a 302 for temporary moves, add the code correctly to your .htaccess, ensure the redirect points to the correct new URL, and test that the redirect works after adding it, confirming the old URL correctly redirects to the new one.