Rick Cogley Central
100% Indispensible or 100% Optional?
Error-handling in RapidWeaver Sites
| Author: | Rick Cogley |
| Revision: | 1 Dec 2008 |
| Updates: | Get updates via RSS feed for this document, or subscribe to updates from Rick Cogley Info. |
| Colophon: | This page was written as a Google Doc, and is published as a Tutorial on Rick Cogley Info via Loghound's PlusKit. |
RapidWeaver from Realmac Software is an outstanding website development application for the Mac, which I use to edit my personal and company websites among others. This tutorial is intended to show the RapidWeaver site author how to enable better error handling in their RW-developed websites, and assumes you know how to use RapidWeaver in general.
Errors take various forms when you are publishing content on the web, due to the dynamic nature of websites themselves. RapidWeaver can ironically be said even to exacerbate this problem, since it makes it so easy to change the filenames and paths of your site's files. If a file is missing, most web servers will return a 404 error, and the resulting page can be pretty spartan.
For better search-engine optimization, in general you want to try to eliminate 404 errors, and while I'll touch on that below, first you need a good 404 error page for when someone enters or clicks on a URL for a file that no longer exists, or, is a misspelling or mis-entry of an existing URL.
Creating an Informative 404 Page with RapidWeaver
As opposed to a "Spartan" default 404 with no extra information, an "informative" 404 page might have links to your top page, your search page, your sitemap or your contact form. If you create your 404 in RapidWeaver, you can add all these things, as well as a widget from Google webmaster tools. Here's how to do it: Add the 404 Page as Styled Text
First, create the 404 page using a "styled text" page type in RapidWeaver. In General Settings in Page Info, uncheck "show in menu", set the folder to, say "/errors" or something similar, and name the page 404.shtml. That folder means you'll find the file in http://yoursite.com/errors/404.shtml. Set the theme to that of your site. 
Note, if you get errors with the file named with an .shtml extension, try changing it to simple .html.
Populate your 404 with Links and a Widget
Next, enter some text and links on your 404, as well as the Google widget for better 404's from Google Webmaster Tools. In Google Webmaster tools, click your registered site, then Tools on the left navigation menu, then "Enhanced 404", to get the script. You can see the script pasted into the screenshot highlighted in pink. It will be white at first, but you can select it, and choose Format, Ignore Formatting. This tells RapidWeaver to treat the script as a script and not visible text. Incidentally, the script text visually turns pink, so that you can tell it is formatted as "Ignore Formatting". Additionally, I gave the title a heading format, by selecting the title text - "Oh Drat - This is the Dreaded 404 'Page Not Found' Error" - and doing Format, HTML, Heading. Pick Heading 1, 2 or 3 etc as appropriate to your site's visual look.
Create the .htaccess in your Site's Root
Now, you have to create an .htaccess text file in your site's root. Create the file, upload it to your root, set its permissions to 644, and point your site's 404 errors at the 404 page you created. If your 404 page is at /errors/404.shtml, then the command in .htaccess is:ErrorDocument 404 /errors/404.shtml
You can upload the file using an FTP client like Transmit, or, using your Hosting Company's "Dashboard" application. For hosting Rick Cogley Info, I use Little Oak hosting, and they have a good dashboard application I can use to upload files and set permissions.
Enable .htaccess in your Apache
You also have to confirm that your web server allows .htaccess files to override the settings in the Apache config file. If you know how to access your Apache config file, confirm it yourself. If you are not sure, either ask your web host company or try it and see. For reference, my Apache config file "httpd.conf" is in:
/etc/httpd/conf/httpd.conf
First enable the mod_rewrite module in Apache. Uncomment the line in httpd.conf that looks like:
LoadModule rewrite_module modules/mod_rewrite.so
Then, for the directory your site is in, enable overriding of the httpd.conf parameters with the AllowOverride line, which is set to None by default. You can do this either generically for all sites, or, per site. I recommend doing it per site. Look for the line that says AllowOverride None.
DocumentRoot "/home/myuser/www.mydomain.com"
ServerName www.mydomain.com:80
<Directory "/home/myuser/www.mydomain.com">
allow from all
AllowOverride All
Options +Indexes
</Directory>
ErrorLog /var/log/httpd/www.mydomain.com_error.log
LogLevel warn
CustomLog /var/log/httpd/www.mydomain.com_access.log combined
</VirtualHost>
Verify the 404 Works
After you do your Apache configs, and save your .htaccess, you can enter a mistaken URL to test. When you use the widget, you can see that it adds some keywords in its search box to assist you in finding the content you seek.
Redirecting Missing Pages with 301 Redirects in .htaccess
Now that your 404 is working, you have a fallback if someone enters an incorrect URL, or, clicks on a link that no longer exists or should point to another page. This is not perfect, of course. If you know that pages are missing or you have renamed pages, you can use 301 Redirects in your same .htaccess. Put the redirects at the top, in front of the 404 rule. Let's say, you have three scenarios that apply:- A blog myblog.php that used to be live in a folder called /weblog and that you have re-entered the path in RapidWeaver to be /blog/ instead, and changed the name of the index file to index.php.
- A page that you deleted, called /weblog/2001/12/Old_Stuff.html
- A sitemap that was located in /sitemap/sitemap.html, but you want to be able to just enter /sitemap after your URL to jump to the sitemap.
Editing the .htaccess
Here's how to edit the .htaccess in your root to make this work. In case 1, you could enter:Redirect 301 /weblog/myblog.php /blogIn case 2, you could enter:
Redirect 301 /weblog/2001/12/Old_Stuff.html /blogIn case 3, you could enter:
Redirect 301 /sitemap/sitemap.html /sitemapIn the end, your .htaccess would look like the following.
Redirect 301 /weblog/myblog.php /blogThis makes some assumptions, and would be slightly different for every situation, but I think you can get the meaning of how it works. The 301 redirect is an excellent way to keep flexibility, and does not count against you in terms of Search Engine Optimization.
Redirect 301 /weblog/2001/12/Old_Stuff.html /blog
Redirect 301 /sitemap/sitemap.html /sitemap
ErrorDocument 404 /errors/404.shtml