Jeremy
Jeremy

Reputation: 123

Redirect loop due to htaccess file

The problem I'm having is that the first URL works and the second one doesn't.

http://www.example.com/podcasts
http://www.example.com/podcast

They're both HTML files, so adding .html to the second one will make it work. It's only when the html extension is stripped away (which is what I want to happen) that the redirect problem appears.

I think the issue is that "podcast" is both a folder and an html file. In other words, there is a folder called "podcast" and there is also a file called podcast.html, the extension of which is automatically stripped away (which was my intention).

So how can I fix this redirect issue? I would like the folder and the html to still have the same names and the html extension to be be stripped away, as it is now.

Here's a copy of my .htaccess file (edit: added L flags)

RewriteEngine On 
RewriteBase / 

#removing trailing slash 

RewriteRule ^(.*)/$ $1 [R=301,L] 

#non www to www 

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

#shtml 

AddType text/html .html 
AddHandler server-parsed .html 

#html 

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^([^\.]+)$ $1.html [NC,L] 

#index redirect 

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.html\ HTTP/ 
RewriteRule ^index\.html$ http://example.com/ [R=301,L]

Pretty sure that the RewriteRule pertaining to %{REQUEST_FILENAME} !-f is causing the issue. The loop doesn't occur for a 404 error.

Ideas?

Upvotes: 0

Views: 859

Answers (1)

Will
Will

Reputation: 1619

Try putting this under your HTML section.

RewriteCond %{REQUEST_FILENAME} !-d

Your -f flag will prevent files from being considered in the rule, but this will exclude directories.

Upvotes: 1

Related Questions