Redirect an HTML Site to WordPress

You are here:
Estimated reading time: 2 min

When moving an HTML site to WordPress, it’s best to use the WordPress permalink structure instead of retaining the .html extension. But this requires creating 301 redirects to keep from losing traffic. Depending on the size of your site, this may mean creating hundreds of redirects.

If the page names don’t change, this can be accomplished using three lines of code to redirect the HTML pages to WordPress PHP.

This article assumes you know how to access and alter the .htaccess file in your hosting account.

Setting the Homepage URL

The first two lines of code in the snippet redirect the homepage to index.php (although you never see this part of the URL in WordPress).

Always make a backup copy of the original .htaccess file before editing. 

Place this code at the top of the .htaccess file in the root directory where the new website resides.

Make sure to replace www.site-name.com with the correct domain names.

You can use either the same site-name or a new one if you are changing domain names.

Redirect results:

Starting URL (HTML site) Result (WordPress site)
https://site-name.com https://site-name.com
https://site-name.com/index.html https://site-name.com
https://site-name.com https://site-name-2.com
https://site-name.com/index.html https://site-name-2.com

Redirecting Interior .html Pages

Even if the homepage is set to redirect, the interior pages of the site will still generate 404 (file not found) errors. Adding the third line of code below redirects any page ending in .html to the WordPress permalink structure.

Make sure to replace www.site-name.com and /page-name/ with the correct domain and page names.

Redirect results:

Starting URL (HTML site) Result (WordPress site)
https://site-name.com/page-name.html https://site-name.com/page-name/
https://site-name.com/page-name.html https://site-name-2.com/page-name/
Make sure to also add redirects for any page names that change.

Redirecting the Domain Name

Once the redirects are added to the .htaccess file, the domain needs to be redirected to the new website. How you redirect the domain name depends on whether the domain name is changing, the web host is changing, or both.

If only the domain name is changing

To redirect the domain, follow these steps:

  1. Login to cPanel. Or, if the old domain is going to be parked at a domain registrar, login to your registrar’s dashboard.
  2. Create a 301 redirect using wildcards. This will redirect every page on the site to the corresponding pages on the new website.

    Setting up a domain wildcard 301 redirect in cPanel

    Setting up a domain wildcard 301 redirect in cPanel

If the web host is changing

If you’re keeping the same domain but changing web hosts, do the following:

  1. Login to the domain registrar where the old domain is hosted.
  2. Change the nameservers to the new host. You can usually find the correct nameservers in your cPanel account.

If the domain name and web host are changing

If you’re changing both the domain and web host, follow these steps:

  1. Login to the host where the old domain is registered.
  2. Change the nameservers to the host where the new site is located.
  3. Add the domain to cPanel using either the Domain Parking or Addon Domain tool.
  4. Create a 301 redirect with wildcards in cPanel.

References:

For more information on DirectoryIndex directives, visit Apache.org.

Tags:

Reader Interactions

Leave a Reply

NOTICE: Permanently closing March 31, 2024. I will be working limited hours until then.