View Single Post
  #19 (permalink)  
Old 01-18-2008, 10:33 AM
wige's Avatar
wige wige is offline
Moderator
WebProWorld Moderator
 
Join Date: Jun 2006
Location: United States
Posts: 2,629
wige RepRank 9wige RepRank 9wige RepRank 9wige RepRank 9wige RepRank 9wige RepRank 9wige RepRank 9wige RepRank 9wige RepRank 9wige RepRank 9wige RepRank 9
Default Re: Canonicalization Prevention Guide

I am glad people have already found the information useful. To address some of the comments....

edhan, I suspect the issue you are experiencing is arising because of a problem in the .php script itself, possibly because the script in question can't handle the filename not being in the REQUEST_URI. If you post (or PM me with) a URL where I can test it and replicate the issue, I may be able to confirm. The order of mod-rewrite directives vs other directives in your .htaccess file should not have any impact on the functionality. Error 500 though indicates an error in the script itself.

Webnauts, I have a question for clarification about one of the snippets you posted, specifically,
Code:
 ########## Require to add trailing slash if not present to avoid cannonicalization issues ###
RewriteCond %{HTTP_HOST}   !^www\.yoursite\.com [NC]
RewriteCond %{HTTP_HOST}   !^$
RewriteRule ^/(.*)         http://www.yoursite.com/$1 [L,R]
The comment indicates that this will add a trailing slash if it is missing, but the tests only look at the HTTP_HOST field, which would not contain a trailing slash. Only the domain name is contained in that field. The request (the portion after get or post in the request) is contained in REQUEST_URI. Did I misinterpret this?

Please note, when doing redirects, R uses a 302 redirect (at least in Apache 2.0-2.2), using R=301 will force the server to respond with a permanent redirect, which is generally preferable so that search engines properly process the redirect.

I'll also add, as DoneInStyle stated above, intellectually, yourdomain.com is preferred over the older, traditional www.yourdomain.com. However, I used www in all my examples because, well, I'm pandering to user expectations. Most servers and hosting companies up to a few years ago forced hosted sites to use www, www was also used to "brand" a company's Internet presence in offline marketing. This has ingrained www into the consciousness of the web-going consumer. It is second nature for users to enter www before a URL when trying to remember an address (as indicated in numerous usability studies, as well as the AOL Personal Information Giveaway - I mean leak) and redirecting a user, even seamlessly, could have the potential of disrupting the user experience, simply by defying the expectations of the user. Also, as most security certificates are issued for the www subdomain, some browsers may issue a warning when users change subdomains when entering or leaving the secure connection. This is all my own opinions, and not really the place to debate which form is better, I just wanted to address the comment and point out that yes, I did use www in all my examples for this reason, and if you prefer the non-www form be aware of this and modify the code accordingly.
__________________
The best way to learn anything, is to question everything.

Last edited by wige; 01-18-2008 at 10:54 AM.
Reply With Quote