Skip to main content

Redirecting Pages Using .htaccess in WordPress

Ryan Lewis avatar
Written by Ryan Lewis
Updated over a month ago

If a page on your website no longer exists, you can redirect visitors to a new page or a different website using the .htaccess file. Redirects ensure a smooth user experience and prevent broken links.


Redirect a Page to Another Domain

To redirect a specific page or directory to another domain, add the following code to your .htaccess file:

RewriteEngine on Redirect 301 /mypage.html http://example.com
  • /mypage.html – the page on your website that no longer exists.

  • http://example.com – the destination domain where visitors should be redirected.


Redirect a Page to Another Page

To redirect a page to another page on the same site, use the following code:

# Redirect from an old page to a new page Redirect 301 /oldpage.html /newpage.html
  • /oldpage.html – the page visitors are trying to access.

  • /newpage.html – the page where visitors will be redirected.

After adding this, whenever someone visits example.com/oldpage.html, they will automatically be redirected to example.com/newpage.html.


Notes

  • Always back up your .htaccess file before making changes.

  • The 301 status code indicates a permanent redirect and is preferred for SEO purposes.

  • Test your redirects after saving to ensure they are working as expected.

Did this answer your question?