| Code | Type | Use Case |
|---|---|---|
301 |
Permanent | Page permanently moved. Passes SEO value to the new URL. |
302 |
Temporary | Page temporarily moved. SEO stays on the original URL. |
307 |
Strict Temp | Like 302, but the request method (POST/GET) is preserved. |
What is an .htaccess redirect?
An .htaccess redirect is a rule in the .htaccess file of an Apache web server that sends visitors from an old URL to a new one. You need redirects when you move pages, change your domain or switch to HTTPS, so that old links and search rankings keep working.
How to make .htaccess redirects
- Click a preset under Common Patterns, for example Force HTTPS.
- For a single page, enter the Old Path and the New URL, select the Type and click Add.
- Check the Rules list and remove the rules that you do not need.
- Click Copy or Download, then upload the file to the root folder of your site.
301, 302 or 307?
- 301: the page moved for good. Search engines move the ranking to the new URL. Use it for most redirects.
- 302: a short-term move. The old URL keeps its ranking.
- 307: a short-term move that keeps the HTTP method, so a POST stays a POST. Use it for forms and APIs.
Frequently Asked Questions
What is .htaccess?
A configuration file for Apache web servers. It sets redirects, access rules, error pages and URL rewrites for one folder and its subfolders, with no change to the main server configuration.
What is the difference between a 301 and a 302 redirect?
A 301 says that the page moved for good, and search engines give its ranking to the new URL. A 302 says that the move is temporary, so the ranking stays with the old URL.
When should I use a 307 redirect?
When the redirect is temporary and the request method must stay the same. A client can change a POST to a GET when it follows a 302. With a 307, it sends the same method again.
Does .htaccess work on Nginx?
No. .htaccess is for Apache only. On Nginx, add the redirects to the server block in the Nginx configuration. The status codes are the same, but the syntax is different.
Must I restart Apache after I change .htaccess?
No. Apache reads .htaccess on every request, so a change works at once. This is why shared hosting plans use it.