Nothing is for sale here. Freewill tips keep the site running. Want to help? → Tip via Paypal
Redirect | 301 Redirect
A 301 redirect is a permanent redirect from one URL to another. It is a powerful technique used to redirect both users and search engines from an old URL to a new URL. In this tutorial, you will be guided through the process of implementing a 301 redirect.- Step 1: Locate or create the .htaccess file
- The .htaccess file is typically located in the root directory of your website. If you can't find it, you may need to enable "show hidden files" in your file manager or FTP client. If the file doesn't exist, you can create a new plain text file and name it ".htaccess". Note that there is no file name before the . (dot) in .htaccess, which is why it may be hidden initially.
- Step 2: Open the .htaccess file
- Using a text editor, open the .htaccess file for editing.
- Step 3: Add the 301 redirect rule
-
To set up the 301 redirect, you'll need to add a line of code to the .htaccess file for each redirect. The basic format is:
Redirect 301 /old-url /new-url
Replace "/old-url" with the path or URL fragment of the old page you want to redirect, and "/new-url" with the destination URL where you want to redirect users.
For example, if you want to redirect "old-page.html" to "new-page.html", the line should look like this:
Redirect 301 /old-page.html /new-page.html - Step 4: Save the .htaccess file
-
After adding the redirect rule, save the .htaccess file. If you're creating a new .htaccess file on your comptuer make sure your text editor doesn't append a .txt extension to it, then upload it to your website.
Be sure you don't have an .htaccess file on your server before uploading one. If you overwrite an existing .htaccess file it could cause issues with your website.
- Step 5: Test the 301 redirect
- To ensure that the redirect is working as expected, open a web browser and enter the old URL. You should be automatically redirected to the new URL. If the redirect is not working, double-check the syntax and paths in your .htaccess file.
- Step 6: Repeat for additional redirects if needed
- If you need to set up multiple 301 redirects, repeat steps 3 to 5 for each redirect, adding a new line for each rule in the .htaccess file.
The 301 redirect is a powerful tool, but it's important to be cautious when implementing it. Mistakes in the redirect rules can cause unexpected behavior or create redirect loops. Always double-check your code and test the redirects thoroughly after implementation.
That's it! By following these steps, you can set up 301 redirects using only the .htaccess file to redirect old URLs to new locations on your website, or even to other websites.