Preparing Your New Site for Structural Changes - Moving Pages
(Page 5 of 6 )
Now look at that first line in the above snippet from the exchange. The server is now instructing the browser or spider that the page has moved permanently to the new address. This allows the search engine to update its records regarding that particular file and begin spidering the new file.
Our Database Table
The database table is quite simple. We need only a couple of columns. In your version you may wish to add descriptions, notes, SE-friendly addresses, etc. but for this illustration we'll keep it as straight-forward as possible.
RedirectContentID (auto number) OldURI NewURI
1 /OldAddress.htm Content.php?ContentID=358
2 /AboutUs.php Content.php?ContentID=234
Using the Data
In our table we have three columns - an ID column, a column for the old location of the file, and a column for the new location of the file. Please note that all paths are from the server root for portability. When we do our redirects we will prepend the server name to the location of the new content as the HTTP 1.1 spec calls for an absolute path (though many browsers accept relative paths).
Pseudo-Code for 404.php
Look at the name of the page that is being requested via the REQUEST_URI environment variable. This will contain the name of the page requested rather than the name of the 404 page currently running as Apache knows enough to understand that this variable will be critical to a 404 page.
Attempt to find the name of the requested file in the database table.
If the name is found:
- Set a header of 301 to tell the visitor or spider that this page has moved permanently.
- Set a location header to relocate the browser or spider to the address of the new page.
If the name is NOT found (a REAL 404 condition)
- Display a search field with some search tips
- Display a feedback form to allow the customer to ask for assistance in finding their content
At this point you may be saying "yes, yes, this is all very nice, where is the CODE??"
Next: The Code >>
More Search Optimization Articles
More By Bill Sterzenbach