【问题标题】:CodeIgniter doesn't display website properly on serverCodeIgniter 无法在服务器上正确显示网站
【发布时间】:2013-08-01 11:34:21
【问题描述】:

我使用 CodeIgniter 框架在 PHP 中创建了一个站点。完成后,我编辑了routes.php 文件并添加了.htaccess 文件以从URL 中删除/index.php/ 部分。

现在,当我尝试在 localhost 中打开它时,它工作正常,我可以访问 http://localhost/mysite 并获得我想要的登录页面。

但是,问题是当我尝试访问服务器上的站点时,出现错误。所以如果我打开类似http://mysite.com 的东西,我会得到 CodeIngniters 的默认 404 页面。如果我指定它们的 URL,我可以打开所有其他页面,例如:http://mysite.com/about,但是当其他人打开该站点时,他会收到一个错误,并且他不知道要输入什么才能绕过该错误。

我应该怎么做才能解决这个问题?提前致谢。

编辑:.htaccess

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

【问题讨论】:

  • 您能告诉我们您对提到的每个文件做了哪些更改吗?
  • 我认为错误出在 htaccess 文件上
  • 你改变了config.php的内容吗?
  • @Dale 我用 htaccess 代码编辑了这个问题@VinodVT 是的,当然。
  • 尝试删除 ?来自index.php?/$1

标签: php codeigniter .htaccess


【解决方案1】:

这个 .htaccess 代码总是对我有用,你可以试试这个:

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

【讨论】:

    【解决方案2】:

    您的 .htaccess 确实引起了一些担忧,您正试图将文件位置作为查询字符串传递,这可能在 CodeIgniter 中有效,但有更好的方法。

    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule .* /index.php [L]
    

    另外,请确保在您的 config.php 中设置了以下选项:

    $config['uri_protocol'] = 'REQUEST_URI';
    

    祝你好运。

    【讨论】:

      【解决方案3】:

      这个 .htaccess 代码有效

      <IfModule mod_rewrite.c>
      RewriteEngine On
      RewriteBase /
      RewriteRule ^index\.php$ - [L]
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteRule . /index.php [L]
      </IfModule>
      

      在配置中

      $config['index_page'] = '';
      

      【讨论】:

      • 没有。它仍然给我 404。
      • 给我们你的 routes.php
      • 和 $config['base_url'] = '你的网站';
      • base_url 已设置。这里是 routes.php:
      • 在路由结束时尝试添加 $route["(.*)"] = 'MasterKontroler';
      猜你喜欢
      • 2013-09-01
      • 2021-11-14
      • 1970-01-01
      • 2012-12-27
      • 1970-01-01
      • 2021-12-16
      • 2013-10-26
      • 2018-06-13
      • 2013-04-12
      相关资源
      最近更新 更多