Blog

Mass Replace Files with a “.html” Extension with a “.php” Extension Including Links
Posted on July 3, 2014 in Command Line, Linux by Matt Jennings

Sometimes it is necessary to use HTTrack Website Copier to inherit a website, including moving it onto a different server, if you do not have FTP access to download the source code directory from the website’s server.

However, when using HTTrack Website Copier the outputted files all have a .html extension. To change the links in those files to have a .php, including the links in these files having a .php extension (like Contact INSTEAD of Contact
) follow the steps below:

  1. If on a Windows machine, download Cygwin. During the installation process of Cygwin make sure you add the mv and basename Linux utilities.
  2. If on a Mac open Terminal.
  3. In the shell, navigate to the directory where you will change .html extensions to .php, type in the code below and press Enter:
    for f in *.html; do mv $f `basename $f .html`.php; done;
  4. In the directory that you are targeting, you will now see that all the .html file extensions have changed to .php.
  5. Inside the new PHP files, to change the .html strings to .php, type in the code below and press Enter:

    grep -lr -e '.html' * | xargs sed -i 's/.html/.php/g'

Leave a Reply