首页 文章

由于htaccess文件导致重定向循环

提问于
浏览
0

我遇到的问题是第一个URL有效,第二个URL没有 .

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

它们都是HTML文件,因此将.html添加到第二个将使其工作 . 只有当html扩展被剥离(这是我想要发生的)时才会出现重定向问题 .

我认为问题是“播客”既是文件夹又是html文件 . 换句话说,有一个名为“podcast”的文件夹,还有一个名为podcast.html的文件,其扩展名被自动删除(这是我的意图) .

那么我该如何解决这个重定向问题呢?我希望文件夹和html仍然具有相同的名称,并且可以删除html扩展名,就像现在一样 .

这是我的.htaccess文件的副本(编辑:添加了L标志)

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]

很确定RewriteRule属于%!-f导致问题 . 404错误不会发生循环 .

想法?

1 回答

  • 1

    尝试将其放在HTML部分下 .

    RewriteCond %{REQUEST_FILENAME} !-d
    

    您的 -f 标志将阻止在规则中考虑文件,但这将排除目录 .

相关问题