codeigniter的重定向不断地将我重定向到index.php

时间:2013-02-28 11:56:07

标签: codeigniter redirect

我正在使用沉闷的重定向:

redirect('/home/login/');

用于未记录用户的时间。但它一直将我重定向到

/index.php/home/login/

虽然我在.htaccess中有这个:

RewriteRule ^(.*)$ /index.php/$1 [L]

1 个答案:

答案 0 :(得分:0)

可能的解决方案1:

制作.htaccess

<IfModule mod_rewrite.c>

    RewriteEngine On
    RewriteBase /#MY_DIRECTORY#

    RewriteRule ^(#MY_DEFAULT_CONTROLLER#(/index)?|index(\.php)?)/?$ / [L,R=301]
    RewriteRule ^(.*)/index/?$ $1 [L,R=301]

    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.+)/$ $1 [L,R=301]

    RewriteCond %{REQUEST_URI} ^system.*
    RewriteRule ^(.*)$ /index.php/$1 [L]

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

</IfModule>

<IfModule !mod_rewrite.c>
    ErrorDocument 404 /index.php
</IfModule>

*编辑My_Application_Folder \ Config.php *

$config['base_url'] = '/#MY_DIRECTORY#';
$config['index_page'] = '';
$config['uri_protocol'] = 'AUTO';

可能的解决方案2:

制作.htaccess

RewriteEngine on
RewriteBase /#MY_DIRECTORY#
RewriteCond $1 !^(index\.php|images|css|js|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1 [L] 

*编辑My_Application_Folder \ Config.php *

$config['base_url'] = '/#MY_DIRECTORY#';
$config['index_page'] = '';
$config['uri_protocol'] = 'AUTO';

注意:#MY_DIRECTORY#位于实时服务器subdom目录(例如first.example.com) - 仅举例说明并在一个系统CI上处理多个应用程序

不要忘记在htaccess或输出自定义库

中设置文件规则
AddDefaultCharset UTF-8

Header unset Pragma
FileETag None
Header unset ETag

1年

<filesMatch ".(ico|pdf|flv|jpg|jpeg|png|gif|swf|mp3|mp4)$">
Header set Cache-Control "public"
Header set Expires "Thu, 15 Apr 2010 20:00:00 GMT"
Header unset Last-Modified
</filesMatch>

2小时

<filesMatch ".(html|htm|xml|txt|xsl)$">
Header set Cache-Control "max-age=7200, must-revalidate"
</filesMatch>

CACHED FOREVER / MOD_REWRITE每次更改

<filesMatch ".(js|css)$">
Header set Cache-Control "public"
Header set Expires "Thu, 15 Apr 2010 20:00:00 GMT"
Header unset Last-Modified
</filesMatch>