How to Create a Custom 404 Error page with .htaccess

Everyone’s encountered those standard 404 error pages that yield little or no information. Most new systems have this feature built in by default and often times are pretty fancy with informative to funny graphics and lots of options on what to do next but, if your working on updating an old site not using dynamically based web pages then, your going to have to add one manually. For your user’s experience, it’s better to provide a helpful error message and links to where they can continue on their quest for information. You don’t want to scare your visitors away do you? Here’s how to add your own custom 404 error page to your website:

If you don’t already have an .htaccess file in your servers root, go ahead and create one. Now you need to instruct .htaccess where your custom error page is. In this example, I have the 404 document which I created with my editor that provides lots of useful information for users to continue browsing my site. Now add this line to your .htaccess file and that’s it!

ErrorDocument 404 /404.html

Disallow hotlinking while allowing requests from robots.txt and favicons

We all hate Leechers. Here’s how to stop them in their tracks from stealing your images and your bandwidth!

Options +FollowSymLinks
RewriteEngine on
RewriteCond %{REQUEST_URI} !(^/robots\.txt|\.ico)$
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?example.com(/)?.*$ [NC]
RewriteRule .*\.(gif|jpg|jpeg|bmp|pdf)$ [F,L]

Creating an .htaccess file on Windows

Everyone who has tried creating a .htaccess on windows knows that Windows Explorer does not accept the ‘.’ character as the first character of a file. For most of you this may be old stuff, but for the newbies, the quick way to create a file that starts with a ‘.’ is actually pretty simple.

Open notepad and save the document with file name .htaccess with the ’save as type’ set to ‘All Files’; or save the document with file name as “.htaccess” including the quotes. Hope this helps someone!

htaccess – How to redirect all http (port 80) requests to https (port 443)

Sometimes you may need to redirect http requests on port 80 to (https) on port 443. This can easily be accomplished with .htaccess.

RewriteEngine on
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^/(.*) https://%{SERVER_NAME}/$1 [NC,R,L]

Using SSH and Unix commands

Having some basic knowledge of SSH and Unix commands is very useful. Developed in 1995, SSH (Secure Shell) was created as a secure alternative to Telnet. Telnet is a protocol allowing for command line access to a Unix, Linux or FreeBSD based remote computer. I’ve listed some basic commands to get you familiar with them.

The cd command is used to move to a specific directory.
Command: cd
Format: cd /directory/to/browse
The cp command will copy the file or folder from the source, to the destination.
Command: cp
Format: cp /directory/source /directory/destination
mkdir creates a directory.
Command: mkdir
Format: mkdir /directory_to_create
The rmdir command deletes a directory.
Command: rmdir
Format: rmdir /directory/to/delete
The rm command deletes a file.
Command: rm -f
Format: rm -f filename
The mv command will rename or move a file stated in the first portion to the name or location stated in the second portion.
Command: mv
Format: mv /directory/you/want/to/rename/or/move /new/directory/name/or/location
This command will tar zip the files in the directory specified in the second portion into a tar file specified in the first portion.
Command: tar cvf
Format: tar cvf filename.tar.gz /directory/you/wish/to/archive
The tar -xvf will extract all files from the tarball specified into the directory you are currently in.
Command: tar -xvf
Format: tar -xvf filename.tar.gz
This will create a zip file, with the name specified in the first portion from the file or directory listed in the second portion.
Command: zip
Format: zip filename.zip /file/or/folder/you/want/to/zip
This command will unzip or un pack the named zip file, into the directory you’re currently in.
Command: unzip
Format: unzip filename.zip
The Ls command lists files, and folders within the directory you specify
Command: ls
Format: ls /directory/you/wish/to/list/files/
This will add a forward slash to the directory names within the directory you specify
Command: ls -f
Format: ls -f /directory/you/wish/to/list/files/
This will show “hidden” files in the directory you specify
Command: ls -a
Format: ls -a /directory/you/wish/to/list/files/
This command shows detailed info about each file in the directory you specify.
Command: ls -l
Format: ls -l /directory/you/wish/to/list/files/

Also, a lightweight, freeware application which supports SSH commands that I use is, PuTTY.

  • Page 1 of 2
  • 1
  • 2
  • >