404 error

404

OMG where am I?

confused baby

Have you ever felt lost?

But what could have happened?

You either clicked on a link and were surprised with a 404 error

-

Maybe you typed the wrong address

You typed a link and bang a 404 error

-

Maybe the page has been moved

You typed a link or clicked on a link

-

Maybe their server sneezed

No matter how you got there

Most 404 errors look like this

404 message

Sooooo......

What could you do?

Make sure your error page looks like your site



You want people to think they are still in your site,
or at least, they have come to the correct site

iinet 404 message

Give them a link to your home page, site map or support page

Don't just re-direct them,
it would be very confusing

iinet 404 message

You could make it fun

fly 404 message
minion 404 message
bike 404 message

How to display your own custom 404 error page

You need a .htaccess file

.htaccess files can be used to ...

-redirecting

-password protection

-custom error pages

-etc

htaccess signpost

A .htaccess file is simply a text file

placed in your root folder

To redirect to your own error page

create a text file

save as .htaccess (with no extension)

ErrorDocument 404 /errors/not-found.html

ErrorDocument 404 /errors/not-found.html

__

The Error command

The type error

Path to custom error page

Some stuff about .htaccess

You can create links for other errors

Informational responses (100–199)

Successful responses (200–299)

Redirects (300–399)

Client errors (400–499)

Server errors (500–599)

ErrorDocument 400 /errors/bad-request.html

ErrorDocument 401 /errors/auth-reqd.html

ErrorDocument 403 /errors/forbid.html

ErrorDocument 404 /errors/not-found.html

ErrorDocument 500 /errors/server-err.html

A few typical error codes

404 = Not Found

404 means the page you have requested is not available

403 = Forbidden

403 means you do not have permission to view the page

500 = Internal Server Error

500 this is about the server and basically means something went wrong
often if you try again it might work

504 = Gateway Timeout

504 the time allowed to reach the server has run out

Some other stuff you can do ...

.htaccess has it's own syntax

You can set your
own home (landing) page

picture of a house

DirectoryIndex [filename here]

If you want your default to be home.html

DirectoryIndex home.html

You can also specify more than one DirectoryIndex

DirectoryIndex index.php index.shtml index.html

You can redirect

redirect

To redirect one page to another URL

Redirect 301 original_URL New_URL

Redirect 301 /relative-url.html http://example.com/full-url.html

__

The Redirect command

The type of redirect (301 - Moved Permanently)

The relative URL of the original page

The full and complete URL of the new page.

When referring to a relative URL, it is relative to the folder that contains the .htaccess

This is generally the root folder of the site

To redirect one whole directory to another

Redirect 301 /old-directory http://example.com/new-directory

To redirect a whole site

Redirect 301 / http://newurl.com

You can hide your .htaccess file

<Files .htaccess>

order allow,deny

deny from all

</Files>

An example of a readwrite rule

Syntax

RewriteRule Pattern Substitution [flags]

* pattern - regular expression, matched against URL-path

* substitution - string that replaces the matched URL-path

* flags - optional, special actions (L, R)

Example:

RewriteRule contest http://example.com/node/123 [L,R]

__

The Redirect command

Request to http://example.com/contest to htttp://example.com/node/123

R = response code (302 – temporary redirect)

L = stop evaluating

.htaccess creation is relatively easy, but ...

They can get pretty complex

man looking at complex math on the board

They can brake your site

..... So be careful

hand breaking boards

Go slowly when building up your .htaccess file

Do One Thing At a Time

one step at a time

If you have a problem Check the Error Logs

Common Problems

man on mountain

Bad Filename

There is only one way to spell .htaccess — it has to begin with the dot,

and it must be in all lowercase letters

.htaccess Disabled or Partly Disabled

Some shared hosting providers disable .htaccess altogether.

Others allow it, but restrict certain directives from being used

Conflicting or Overridden Directives

If you have multiple nested directories, it's possible for each one to have its own .htaccess file.

Every .htaccess file from the root, through each nested directory,

applies — they are read in order, descending down the directory tree.

recap

404 errors are boring and unhelpful

Make yours:

Interesting

Helpful

Funny

... or all of the above

Remember keep them in your site


and do not simply redirect them to the home page

You can create custom error pages for a range of errors

.htaccess files are simply text files

They can be simple to write

but

Be careful they can break your site

thank you

the end