View Single Post
  #9 (permalink)  
Old 01-16-2008, 12:21 PM
wige's Avatar
wige wige is offline
Moderator
WebProWorld Moderator
 
Join Date: Jun 2006
Location: United States
Posts: 2,650
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: .htaccess Help!!

Gary,

As far as the four lines, I think you may need to at the very least modify the first conditional so that .php files are handled.

RewriteCond %{REQUEST_FILENAME} !\.(jpg|jpeg|gif|png|css|js|pl|txt|php)$

Otherwise you have an endless loop. You are testing that the filename ends with a . and one of the listed extensions,, and if that fails you are redirecting the user to a page that has an extension not in the list - this causes an endless loop of redirects. The next two lines check if the requested file is a directory or a normal file, which basically means that the file has an associated MIME type. So the psuedocode for these for lines would be:
If the name of the requested file does not end in .jpg, .jpeg, .gif, .png, .css, .js, .pl, .txt or .php, and if it is not a directory that exists, and it is not a "regular file" (which includes html, htm and a few others) that exists, redirect the user to index.php.

One of the key things is that !-f, which checks if the requested document is a regular file, also tests if that file actually exists. This rule is applied before the ErrorDocument directive, so the user will be redirected to index.php, regardless of what you set to the ErrorDocument to.

On the basis that these four lines only handle security-like operations - preventing access to certain file types and testing if the files exist - and do not do any functional file name manipulations, removal of these lines should not have impacted your CMS, in any way I can think of. After removing the files, what broke, or what happened that shouldn't have?

By the way, I just saw an error in one of the lines I gave you. See my correction at the bottom.

Michael,

I tried to replicate the issue that you report, visiting http://www.christian.healing-prayer.net but I was redirected properly (I think) to http://www.christian-healing-prayer.net. I also tried it without the www subdomain, and was redirected to the same place. I did not get the error messages that you cite. Is there a specific URL that I should test to replicate the issue?

Looking at the error messages themselves, it looks more like a scripting error (bad root directory specification perhaps?) than an issue with the .htaccess file, but without replicating the problem I can't say for sure. In the .htaccess file itself, the only thing I might change is:

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]*/)*index\.html? [NC]
RewriteRule ^(([^/]*/)*)index\.html?$ http://www.christian-healing-prayer.net/$1 [R=301,L]

I take it you are attempting to remove the filename from requests ending with index.html. Not a bad idea as it helps prevent a certain canonicalization issue. However, the lines to achieve it seem overly complex, and with anything that is complex, you have the chance of errors. For example, if you at some point create a folder that is ten characters long, the test will fail and the redirection won't happen ({3,9} would prevent it). Unless there is a specific issue that this requirement is intended to avoid, I would replace the two lines with:

RewriteRule ^(.*)/index\.html http://theticketlodge.com/$1/ [R=301, L]

Bleep. I just realized there is an error in this line. Sorry folks. See below for the corrected version.

Error Correction

I previously mentioned using RewriteRule ^(.*)/index\.php http://theticketlodge.com/$1/ [R=301, L] to remove the index.php from the end of a URL to prevent canonicalization errors. However, I just realized that this would not work on requests for the root index (http://www.yourdomain.com/index.php would resolve to http://www.yourdomain.com//). Sorry for the confusion. The correct way to handle this would be with two different rules, one which addresses the main root, and one which addresses all sub folders (regardless of depth in the site, could be sixteen directories deep, only need one rule). This is necessary because there are limited ways to handle the starting slash. You also need to have the flexibility to still include the word index in file names, so just testing for filenames ending with index.php or index.html would not be ideal. The following two lines will handle the issue properly, and it is script-safe, handling index.php and index.html.

RewriteRule ^/index\.(php|html)$ http://theticketlodge.com/ [R=301, L]
RewriteRule ^(.*)/index\.(php|html)$ http://theticketlodge.com/$1/ [R=301, L]
__________________
The best way to learn anything, is to question everything.
Reply With Quote