On occasion, I get questions like "I created a file called blahblahblah.php or blahblahblah.html using Notepad, and after uploading it to my website and testing it with my browser, I get a 404 File Not Found error. What do I do?" Another variant of this question is "I tried to save my file as blahblahblah.pl but when I uploaded it to my website, I can only find blahblahblah.pl.txt. How do I get the file to be blahblahblah.pl?" This brief article explains how you can solve this type of problem.
If it's a "File Not Found" error that you have, before we proceed to fixing the problems created by Notepad, it is important to first eliminate the possibility that you uploaded the file to the wrong directory.
Web servers are configured so that they serve files only from certain locations. They don't, for example, display your email from your mail folders for all to see. Typically, on your web hosting account, you have to upload your files into a directory called "www" or "public_html". Find out from your web host where you need to upload your files so that they will be displayed correctly.
If you have checked and know for sure that you have not committed this error, move on to the next section.
The other possible reason for the error is Notepad. Notepad, up to the current version, has the practice of adding a ".txt" extension to your files even when you don't specify it. So if you give your file a name of "blahblahblah.html", Notepad will change the name to "blahblahblah.html.txt" without informing you. Compounding this problem is Windows Explorer's policy of not telling you the full filename of your files. Hence if you use Explorer to check the file, it will only show "blahblahblah.html".
If you have already saved your file, the best way to solve this is to first force Explorer to always show you the file extension, and then change the filename to the correct one. This is good practice anyway, since always being able to see the full filename probably improves your system's security — you'll be less likely to be tricked by all those scams asking you to click a file that appears to be a picture but is actually a program.
Open Windows Explorer (also known as "My Computer" or "Computer" on the Windows desktop and the Start Menu). Navigate to the place you saved the file. Click the "Tools" menu on the menu bar in Explorer (the menu bar is at the top of the Explorer window, underneath the window title). Click the "Folder Options" item in the popup menu that appears. A dialog box appears. Click the "View" tab at the top of the window. Look for a setting "Hide file extensions for known file types" and uncheck the box beside it to disable it. If you want to always see the file extension in all folders, click the button "Apply to All Folders" (otherwise don't). Then click "Apply" and then "OK".
You should now be able to see your file as its true name, be it "blahblahblah.php.txt" or "blahblahblah.html.txt" or whatever. Now click once on the filename. Explorer will now allow you to change the filename. If this is not true, select the filename and hit the F2 key on the keyboard. Delete the ".txt" extension, leaving the filename as "blahblahblah.php" (without the quotes) or "blahblahblah.html". Make sure there are no trailing dots or spaces - that is, make sure the filename is really "blahblahblah.php" and not "blahblahblah.php." with a trailing dot or the like.
When you hit the ENTER key, Windows will issue a warning about the dangers of changing filenames. Allow the name change to take place.
While this fixes the problem, read the next section to find out how you can avoid having to repeatedly do this in future, every time you use Notepad.
When you want to force Notepad to save a file without the ".txt" extesion, save the file as "blahblahblah.php", including the quotes, in the Save As dialog box. When you include the quotes, Notepad will save the file with the blahblahblah.php name literally, without adding the txt extension. Note that I have only tested this with the Notepad included with Windows XP. I don't know if this will work in other versions.
Alternatively, you may prefer to get a better ASCII text editor. There are numerous free ones on the Free Programmer's Text Editors and ASCII Text Editors page. Don't worry about the "programmer's editor" bit - despite its grandiose name, programmers' editors are simple ASCII text editors with additional features to make it easier to work with than Notepad.
Do you find this article useful? You can learn of new articles and scripts that are published on thesitewizard.com by subscribing to the RSS feed. Simply point your RSS feed reader or a browser that supports RSS feeds at http://www.thesitewizard.com/thesitewizard.xml. You can read more about how to subscribe to RSS site feeds from my RSS FAQ.
This article is copyrighted. Please do not reproduce this article in whole or part, in any form, without obtaining my written permission.
It will appear on your page as: