Hasty Decisions
|
|
I’ve been running TulsaRockNRoll.com since 2001. In the beginning I was running apache on my home computer over a DSL connection which worked pretty good. I decided to make use of server side includes (SSI) to make the management of my site easier. I didn’t want to go through the mess of renaming my entire site from HTML to SHTML file extensions so I decided to just tell apache to treat HTML files as SHTML files so I could take advantage of the features without going through a big headache.
Eventually it was time to move to a web host. I uploaded all my files and quickly discovered that their web server package didn’t recognize SSI on HTML file extensions. There was no way to modify the server configuration since it was a shared host, I had already re-pointed my DNS configuration to the new host so it was crunch time. I did the unthinkable. I ran several search and replace commands to move the include content directly into the HTML files. I made sure to put the code in comment blocks (i.e. <!– CODE START –> etc.) to make it easier to undo in the future. It was a dirty way to do it but it worked.
The New Challenge – HTML to PHP
Now it’s 2011. I’m running my own server through a remote host which I use to run all my sites (best move I’ve ever made). I decided it was time to get back to a dynamic web development environment. This meant renaming over 500 HTML files to PHP, uploading them to the server and re-pointing all incoming http requests from the HTML versions to the PHP versions.
Renaming files is easy enough in Windows 7 is easy enough but dealing with hundreds of subfolders is tedious to say the least. I searched for software to automate the process but everything I ran across was so old it wouldn’t install on my system. I ended up going through the file tree in Dreamweaver to rename them all by hand.
The next issue was getting all the site-wide links to point to the new PHP versions of the old files. Much of my site’s directory structure is setup to end in / to make scripting upgrades easier but I developed that methodology mid-way in the site’s life-span. During the renaming process Dreamweaver was smart enough to update several of the links, but there were still hundreds of files with incorrect links left. Fortunately Dreamweaver has a site-wide search and replace feature. It would be tempting to just replace all HREFs that end in .html” with .php” but that would affect several external links which were built in to the site. I ended up using the global search and replace on full URLs to get all the links updated properly.
I uploaded a handful of the PHP files which I knew referenced different scripts on the site to find any bugs that might be around when I updated the site. I fixed some minor issues that way. Finally it was time to upload the new files. I used Dreamweaver’s Synchronize Sitewide option and uploaded all the renamed files. Once everything was uploaded I found out that when an index.html is in the same folder as index.php the server automatically picked the index.html file. Not quite what I was hoping for. Fortunately I found a good Linux batch command to take care of it. The batch command does a recursive delete on the specified file parameter. See below:
find . -name *.html -exec rm -i '{}' \;
More Issues
Before they invented AJAX methodology I was effectively using AJAX methods on my site for the image galleries. Apparently when I moved to my new server, the system went from case-insensitive to case-sensitive. My early image editing software saved jpeg files with an uppercase .JPG file extension. My JavaScript gallery generators were all looking for lowercase .jpg file extensions. So for the past couple of months I’ve had about one hundred or so blank galleries from the 2001 to 2002 period . Note: if you have issues on my sites please let me know, thanks
. Of course, as I learned earlier Windows 7 doesn’t have a recursive file renaming feature. I ended up renaming via the command prompt one folder at a time.
Redirecting from HTML to PHP
As anyone with basic SEO knowledge knows, when you change a file location/name on the server you MUST issue a 301 permanent redirect to the new location/name. This was easy when I did the conversion on this site. The two lines below in .htaccess took care of the majority of the work.
RedirectMatch 301 (.*)default\.asp$ http://www.example.com$1 RedirectMatch 301 (.*)\.asp$ http://www.example.com$1.php
So I assumed the following would work with my PHP conversion:
RedirectMatch 301 (.*)index\.html$ http://www.example.com$1 RedirectMatch 301 (.*)\.html$ http://www.example.com$1.php
How wrong I was! The code was forwarding my pages to the directory with /index.php appended. So it might read http://www.tulsarocknroll.com/musicvideos/index.php when I was really wanting http://www.tulsarocknroll.com/musicvideos/. This turned out to be quite a nightmare as I searched the web and tried different ways to get the forwarding worked out. I finally ended up using mod_rewrite to do the index forwarding and I had to create an individual entry for every other non index PHP file on the site:
RewriteEngine on
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*index\.html\ HTTP/
RewriteRule ^(.*)index\.html$ http://www.example.com/$1 [R=301,L]
RedirectMatch 301 /news/20050228/seven.wounds.html
http://www.example.com/news/20050228/seven.wounds.php
...
You can imagine it took a lot of work to hunt down every singe non index file on the site!
Moving On
As you can see it took a full nights work to get my site converted to PHP. Everything is identical to the user (with the exception of the fixed galleries) but now I’ll be able to begin moving the hard coded portions of the site over to PHP include files which will save a great deal of time with modifications in the future. I hope you were able to gain some knowledge from this article. If I didn’t bore you to death, I’ll see you next time!
- Emmett
Tags: apache, development, dreamweaver, html, linux, php, web design



Thanks for sharing the gory details of your experience.
If you find yourself needing to do mass renaming of files again, get yourself a copy of Cygwin, which is free and gives you Linux-type tools for manipulating your files, including the bash shell and the find command. For example, you could do this to change every .JPG to .jpg
for i in `find . -name \*.JPG -print`
do
mv $i ${i%.JPG}.jpg
done
I appreciate the info Michael. Linux commands certainly beat out the commands that come with Windows by a long shot.
how can i convert my html theme to wordpress theme?