[英]htaccess issue causing internal server error too many redirects
所以我在使用.htaccess进行游戏,以在我的codeigniter应用程序中使用干净的URL。
简而言之,我正在尝试:
1)删除网址中的index.php(永久重定向)
http://localhost/directory/index.php*
to
http://localhost/directory/*
http://my.domain.com/index.php*
to
http://my.domain.com/*
2)将某些控制器的请求重写为index.php / [controller_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
返回空字符串吗?)
# Rewrite CI certain controllers
RewriteCond %{THE_REQUEST} directory/(home|other_controller) [NC]
RewriteRule ^(.*)(home|other_controller)(.*)$ /$1index.php/$2$3 [NC,L]
第二期 :
这不适用于http://localhost/dir/home
给出内部服务器错误(重定向太多)。 但是,如果我测试添加了R=301
代码,它将成功重定向到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]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.