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.
Setting the Homepage URL
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).
Place this code at the top of the .htaccess file in the root directory where the new website resides.
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/index.html | https://site-name-2.com |
Redirecting Interior .html Pages
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.
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/ |
Redirecting the Domain Name
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:
- Login to cPanel. Or, if the old domain is going to be parked at a domain registrar, login to your registrar’s dashboard.
- 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
If the web host is changing
If you’re keeping the same domain but changing web hosts, do the following:
- Login to the domain registrar where the old domain is hosted.
- 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:
- Login to the host where the old domain is registered.
- Change the nameservers to the host where the new site is located.
- Add the domain to cPanel using either the Domain Parking or Addon Domain tool.
- Create a 301 redirect with wildcards in cPanel.
References:
For more information on DirectoryIndex directives, visit Apache.org.
Leave a Reply