【问题标题】:.htaccess in Codeigniter is not working in remote serverCodeigniter 中的 .htaccess 在远程服务器中不起作用
【发布时间】:2018-06-12 09:21:33
【问题描述】:

.htaccess 文件在我的本地主机中运行良好 但是当我将它上传到远程服务器上时,重定向无法正常工作。

当我使用任何用户登录然后尝试从站点注销时,它再次显示我已登录,但它在我的本地 Web 服务器上工作正常

RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]

<Files "index.php">
AcceptPathInfo On
</Files> 

这是我的注销控制器

  <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');


 class logout extends CI_Controller { 

public function __construct()
{
     parent::__construct();
}

function index()
{
    $this->home_model->unsetsessions();
    redirect('', 'refresh');
}
}?>

【问题讨论】:

  • 这应该不是您的 .htaccess 的问题。请让我们仔细看看您的控制器操作。
  • 是的,这不是您的 .htaccess 问题,而是您的控制器代码有问题,或者可能是不正确的 base_url。如果您可以发布您的注销代码,可以提供更多帮助。
  • 我已嵌入注销控制器
  • 不知道您在模型中的 unsetsessions() 中使用了什么。但我希望您使用正确的方法来破坏会话。关于你的重定向,不要这样做指定你想要重定向的控制器名称,如果你想重定向到你的家,你可以试试redirect(base_url(),'refresh')
  • 等等。您能否确认您的 Web 服务器使用的是 Apache,而不是 IIS? IIS 不支持.htaccess

标签: php .htaccess codeigniter redirect


【解决方案1】:

这个 .htaccess 在我的 CI 项目中运行良好:

<IfModule mod_headers.c>

    # activate RewriteEngine
    RewriteEngine on

    # delete index.php from URL
    RewriteCond $1 !(index\.php|robots\.txt|humans\.txt|license\.txt|sitemap\.xml|assets)
    RewriteRule ^(.*)$ index.php?/$1 [QSA,L]

    # sitemap.xml to /sitemap
    RewriteRule ^sitemap\.xml$ index.php/sitemap [L]

    # no-www to www
    #change DOMNIO.COM
    RewriteCond %{HTTP_HOST} ^DOMNIO.COM$
    RewriteRule (.*) http://www.DOMNIO.COM/$1 [R=301,L]

</IfModule>

<IfModule !mod_rewrite.c>

    # If we don't have mod_rewrite installed, all 404's
    # can be sent to index.php, and everything works as normal.
    ErrorDocument 404 /index.php
</IfModule>

【讨论】:

  • 其实我的问题是当我点击注销时它没有正确注销然后当我按 F5 并刷新然后它被注销
猜你喜欢
  • 2011-06-10
  • 2017-06-05
  • 1970-01-01
  • 2018-06-09
  • 2014-12-23
  • 1970-01-01
  • 1970-01-01
  • 2017-04-23
相关资源
最近更新 更多