Knowledge Base

How to redirect all your visitors to a new location

Often web developers need to redirect a visitor to another part of their website, another domain or just refresh the page itself with an updated version. Server side techniques have the advantage of wide acceptance, although their use requires access to the web server. Conversely client side methods are available to all content writers, but experience mixed results.

JavaScript

Aimed at creating dynamic pages JavaScript is usually overkill for a simple redirect. Such examples include:

<SCRIPT>window.location.replace("/aaaa");</SCRIPT>

Since not all browsers support JavaScript it should never be used to control access to a site. With the above code and scripting disabled the user would see just a blank page. With no evidence your organisation even exists.

Meta Refresh tag

<meta http-equiv=refresh content="1 URL=http://www.example.org/bar">

This tag causes the page to redirect to the new URL after 1 second.

Such tags are not recommended, WCAG 7.4 and 7.5 forbid "periodically auto-refreshing pages" and the use of "markup to redirect pages automatically".

Alternatively by entering a refresh interval of 0 the page reloads instantly. A method best used when you are unable to deploy server side redirects.

Server Side "3xx" Redirects

Each web server handles the configuration of redirects differently. While apache allows web developers to edit the '.htaccess' file to store permanent and temporary redirects other such as Microsoft's IIS require administrative access.

301 Moved Permanently

The requested resource has moved to a new permanent URL. The client should store this and not check again until it's cache is cleared.

Best used when content has moved for the foreseeable future.

307 Temporary Redirect

The requested resources has moved to a new location, however the client should continue to check the existing location as the move is temporary.

Redirect once and once only

Redirects have their place, but can be over used. Try to avoid redirecting to one page, which redirects to another and so on. Keep it simple.

Further Information

The Sitemorse Knowledge Base is the repository of knowledge about the Sitemorse system.

Every time a new feature is added, a question asked or anything our technical team believe might be appropriate is recorded here.

Categories