Apache Redirects to the Rescue

Posted by Max Dunn Sat, 07 Oct 2006 19:36:00 GMT

There are a couple of technical problems with my web site. The first is that to get into this blog, you need to add the trailing slash at the end of “typo” like this:

http://www.maxdunn.com/typo/

Otherwise, the wiki gives a page not found error for the “typo” page. Of course, when most people type in the URL manually, they won’t add the trailing slash and then get confused when it doesn’t pull up my blog.

I have tried various things in the Rails routing.rb file to correct for this, but none worked. However, a simple change to .htaccess did the trick:

RedirectMatch permanent ^/typo$ http://www.maxdunn.com/typo/

Now another problem I have is that my ISP Site5 maps maxdunn.com to www.maxdunn.com and there is no way to turn this off. This causes several problems:

  • When logged into www.maxdunn.com, you won’t be logged in if you access it as maxdunn.com.
  • If someone first accesses the site using maxdunn.com, then the page cache will create all links as maxdunn.com and serve these up, even if the page is later accessed as www.maxdunn.com.
  • If the site is accessed with both maxdunn.com and www.maxdunn.com, then Google and other search engines will think these are two sites and neither will be ranked as highly.

To fix this problem, there is another simple .htaccess addition that will redirect all maxdunn.com requests to www.maxdunn.com:

RewriteCond %{HTTP_HOST} ^maxdunn.com$ [NC]
RewriteRule ^(.*)$ http://www.maxdunn.com/$1 [L,R=301]

Posted in ,  | no comments

Comments

(leave url/email »)

   Comment Markup Help Preview comment