.htaccess文件导致重定向循环

时间:2015-06-04 03:41:36

标签: php apache .htaccess mod-rewrite redirect

我的.htaccess文件导致重定向循环并且不确定原因!

这是我当前的.htaccess文件:

DirectoryIndex index.php

<IfModule mod_rewrite.c>
# Turn on URL rewriting
RewriteEngine On

# Put your installation directory here:
# If your URL is www.example.com/, use /
# If your URL is www.example.com/kohana/, use /kohana/
# RewriteBase /

# Do not enable rewriting for files or directories that exist
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# For reuests that are not actual files or directories,
# Rewrite to index.php/URL
RewriteRule ^(.*)$ index.php/$1 [PT,L]

</IfModule>

2 个答案:

答案 0 :(得分:0)

试试这个.htaccess以避免循环错误:

DirectoryIndex index.php

<IfModule mod_rewrite.c>
# Turn on URL rewriting
RewriteEngine On
RewriteBase /

# Do not enable rewriting for files or directories that exist
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# For reuests that are not actual files or directories,
# Rewrite to index.php/URL
RewriteRule ^((?!index\.php).*)$ index.php/$1 [NC,L]

</IfModule>

答案 1 :(得分:0)

我注意到在使用Linux Apache时(对版本不太确定),我的网络运行良好。

然而,在使用Windows Apache / 2.4.29(Win64)时,完全相同的代码(包含静态html文件和htaccess的整个文件夹的复制/粘贴)不起作用。我不得不添加“RewriteBase”标签:

RewriteBase /

我相信一些默认值已更改,并且它被重定向到不同的文件夹(其中index.html显然不存在)