If you want to create a redirect from ‘example.com/about’ to ‘example.com/about-us’, you can do so by editing the ‘.htaccess’ file in the root directory of your website. This guide will walk you through the process step by step.
Steps to Create a Redirect in .htaccess
1. Access Your .htaccess File
Open your .htaccess file for your website. See How-to edit your .htaccess file
2. Backup Your .htaccess File
Before making changes, download a copy of the file to your computer as a backup. This ensures you can restore the original file if something goes wrong.
3. Add the Redirect Code
Open your .htaccess file in a text editor and add the following code:
# Redirect /about to /about-us Redirect 301 /about /about-us
- Explanation:
- ‘Redirect’ specifies the redirect directive.
- ‘301’ indicates a permanent redirect, which helps with SEO.
- ‘/about’ is the original path.
- ‘/about-us’ is the destination path.
4. Save and Upload
- Save the changes to your .htaccess file.
- Upload the updated file back to your website’s root directory if you edited it locally.
5. Test the Redirect
- Open a browser and go to ‘example.com/about’
- You should be automatically redirected to ‘example.com/about-us’.
Common Issues and Troubleshooting
- Redirect Loop: Ensure you don’t already have conflicting redirect rules in the .htaccess file. Check for other rules involving ‘/about’ or ‘about-us’.
- File Not Found Errors: Verify the correct paths and ensure that both ‘/about’ and ‘/about-us’ exist or are set up as intended.
Alternative Redirect Method: Using mod_rewrite
If you need more control or want to redirect based on conditions, you can use ‘mod_rewrite’ rules. Add the following to your .htaccess file:
RewriteEngine On RewriteRule ^about$ /about-us [R=301,L]
- Explanation:
- ‘RewriteEngine On’: Enables the mod_rewrite module.
- ‘^about$’: Matches the exact URL ‘/about’.
- ‘/about-us’: Redirects to this destination.
- ‘[R=301,L]’: Sends a 301 status and stops further rules from processing.
By following these steps, you can effectively manage URL redirects, ensuring users and search engines are seamlessly directed to the correct pages.