【问题标题】:codeigniter's redirect redirects me to index.php constantlycodeigniter 的重定向不断将我重定向到 index.php
【发布时间】:2013-02-28 11:56:06
【问题描述】:

我正在使用一个无聊的重定向:

redirect('/home/login/');

当用户未登录时。但它不断将我重定向到

/index.php/home/login/

虽然我的 .htaccess 中有这个:

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

【问题讨论】:

  • 这可能对你有帮助:stackoverflow.com/questions/15017448/…
  • 谢谢。它有帮助!它总是在不从配置文件中删除 index.php 的情况下工作,因为我在早期的项目中没有使用重定向。您应该将此作为答案发布,以便我投票给您。

标签: codeigniter redirect


【解决方案1】:

可能的解决方案 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>

*编辑我的应用程序文件夹\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] 

*编辑我的应用程序文件夹\Config.php*

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

注意:#MY_DIRECTORY# 位于实时服务器子目录(例如 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>

【讨论】:

    猜你喜欢
    • 2018-08-06
    • 1970-01-01
    • 2011-02-21
    • 1970-01-01
    • 2013-01-21
    • 1970-01-01
    • 2016-06-02
    • 1970-01-01
    • 2020-01-24
    相关资源
    最近更新 更多