Apache htaccess问题导致内部服务器错误重定向过多

Apache htaccess问题导致内部服务器错误重定向过多,apache,.htaccess,codeigniter,mod-rewrite,Apache,.htaccess,Codeigniter,Mod Rewrite,因此,我正在使用.htaccess在我的codeigniter应用程序中创建干净的URL 简言之,我试图: 1) 删除URL中的index.php(永久重定向) 2) 将某些控制器的请求重写为index.php/[controller\u name] http://localhost/directory/controller1* to http://localhost/directory/index.php/controller1* http://my.domain.com/control

因此,我正在使用.htaccess在我的codeigniter应用程序中创建干净的URL

简言之,我试图:

1) 删除URL中的index.php(永久重定向)

2) 将某些控制器的请求重写为index.php/[controller\u name]

http://localhost/directory/controller1* 
to 
http://localhost/directory/index.php/controller1*

http://my.domain.com/controller2* 
to 
http://my.domain.com/index.php/controller2*
我的htaccess文件当前如下所示:

Options +FollowSymlinks

RewriteEngine On
#RewriteBase /

# Redirect index.php 
RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
RewriteCond %{THE_REQUEST} !/system/.*
RewriteRule ^(.*)index\.php((/)(.*))?$ /$1/$4 [R=301,L]
第一期

这不适用于
http://localhost/dir/index.php/controller1
。 改为重定向到
http://localhost/dir/controller1
,它将重定向到
http://localhost//controller1
$1
返回空字符串?)

第二期

这不适用于
http://localhost/dir/home
给出内部服务器错误(重定向太多)。 但是如果我测试添加了
R=301
code,它将成功重定向到
http://localhost/dir/index.php/home
。但这不是我想重定向的,我只需要重写它

请告知……)

试试这个:

RewriteEngine On 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ index.php/$1 [L]
您可以将其放在引导文件(index.php)所在的目录中

如果有FastCGI实现,则需要在重写规则中添加问号:

RewriteEngine On 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ index.php?/$1 [L]
试试这个:

RewriteEngine On 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ index.php/$1 [L]
您可以将其放在引导文件(index.php)所在的目录中

如果有FastCGI实现,则需要在重写规则中添加问号:

RewriteEngine On 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ index.php?/$1 [L]

谢谢@Repox,但这会重写
http://localhost/directory/controller
http://localhost/index.php/controller
,而不是
http://localhost/directory/index.php/controller
simple。。。只要加上它。。。或者在htaccess@Brian,是否可以通过regex添加它,而不显式写入dir名称或rewritebase?所以这个.htaccess文件可以移植到本地和生产环境中..谢谢@Repox,但这会重写
http://localhost/directory/controller
http://localhost/index.php/controller
,而不是
http://localhost/directory/index.php/controller
simple。。。只要加上它。。。或者在htaccess@Brian,是否可以通过regex添加它,而不显式写入dir名称或rewritebase?因此,该.htaccess文件将可移植到本地和生产环境中。。