To avoid “404 File Not Found” Error!’s after deleting webpages in the context of a website update, it’s often useful to redirect these webpages to a new url. There are at least 2 major different forms of web page redirection : Client-side Redirection & Server-side Redirection.
The best and safest way to this is the “301 Redirect“. The following tutorials describe the “301 Redirect” method :
- Steven Hargrove : How to redirect a webpage, the smart way
- Steven Hargrove : Understanding webpage redirection, the smart way
- Wikipedia : URL redirection
- Hochmann Consultants : The Difference Between 301 and 302 Redirects
There are different ways to set up an “301 Redirect“. Using .htaccess to accomplish the 301 redirect is highly suggested due to it being fairly convenient to manage, rather than setting redirects on each individual page, you can simply add the redirect code to the .htaccess file. An Online .htaccess editor to configure the redirection is offered by Hideyo Ryoken & Masato Mannen.
A php sample code to redirect an individual page permanently to a new location is shown hereafter :
- header( “HTTP/1.1 301 Moved Permanently” );
- header( “Status: 301 Moved Permanently” );
- header( “Location: http://www.new-url.com/” );
- exit(0); // This is Optional but suggested, to avoid any accidental output
If the redirection is only temporary, you should use the “302 redirect” method. A php sample code to redirect an individual page temporary to a new location is shown below :
- header(”Location: http://www.NewTemporaryWebAddress.com”);