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:
- If on a Windows machine, download Cygwin. During the installation process of Cygwin make sure you add the
mv
andbasename
Linux utilities. - If on a Mac open Terminal.
- In the shell, navigate to the directory where you will change
.html
extensions to.php
, type in the code below and pressEnter
:for f in *.html; do mv $f `basename $f .html`.php; done;
- In the directory that you are targeting, you will now see that all the
.html
file extensions have changed to.php.
- Inside the new PHP files, to change the
.html
strings to.php
, type in the code below and pressEnter:
grep -lr -e '.html' * | xargs sed -i 's/.html/.php/g'