If a page on your website no longer exists, and you want to redirect visitors to a new page or website, you can use the .htaccess file for immediate redirection. This is especially useful for maintaining SEO value and providing a better user experience when URLs change.
- Redirect from a specific page to a different domain:
RewriteEngine on Redirect 301 /mypage.html http://example.comThis will redirect anyone visiting
yourdomain.com/mypage.htmltohttp://example.com. - Redirect from one page to another page on the same domain:
Redirect 301 /oldpage.html /newpage.htmlThis will redirect
yourdomain.com/oldpage.htmltoyourdomain.com/newpage.htmlautomatically.
Tips:
- Always back up your
.htaccessfile before making changes. - Use
301for permanent redirects to preserve SEO rankings. - After editing
.htaccess, clear your browser cache to test the redirect. - If you are using WordPress, ensure that custom
.htaccessrules are placed above the# BEGIN WordPressline to avoid conflicts.