Are you planning to redesign your HTML website in .php script? If yes is your answer then file extension of your website would be changing to .php from .html once you finish the redesigning process. When you upload this .php version in the server without properly redirecting all .html URLs, your website will show 404 errors for all existing URLs that got indexed.
If you have no idea about how to do .html to .php redirection, don’t panic. Here I have given a simple tutorial to redirect .html URLs in your website to .php file extension using .htaccess.
Steps To Redirect all .html URLs to .php Using .htaccess
Step 1: To get started, log into your website cPanel.
Step 2: Now open up File Manager as shown in the screenshot below.
Step 3: Once you have opened the “File Manager“, right-click on “.htaccess” file and choose “Edit“.
Note: If you can’t find “.htaccess” file in your server, then you haven’t enabled “Show Hidden Files” option. Enable it by clicking on “Settings” in File Manager and then by ticking the “Show Hidden Files” box.
Step 4: Now add the code given below to .htaccess file and click on “Save“.
RedirectMatch 301 (.*)\.html$ $1.php
That’s it. Now you have successfully redirected all .html URLs to .php file extension.
If you would like to redirect only a specific URL like index.html to index.php, then you will have to add the following code in .htaccess:
RewriteRule ^index\.htm$ index.php [NC,R]
If you encounter any issues while following this tutorial, do let me know via comments.
Leave a Reply