【问题标题】:codeigniter returns 404 for everything inside subfoldercodeigniter 为子文件夹中的所有内容返回 404
【发布时间】:2015-08-31 06:51:15
【问题描述】:

在我的开发环境(Mac OS、Apache、WP 文件夹中的 CI 应用程序)中,我的应用程序运行良好。今天我将它部署到服务器(Ubuntu Server、Apache、WP 文件夹中的相同 CI 应用程序),我尝试的所有内容都返回 404 页面。

这是我的应用程序/.htaccess:

SetEnv CI_ENV development

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

mod_rewrite 已在此服务器中启用。

在我的 config.php 中我已经尝试过:

 $config['base_url'] = 'http://server/app/';

 // problem in both situations
 $config['index_page'] = 'index.php';
 $config['index_page'] = '';

这里有什么问题?当我转到http://server/app/index.php 时,我收到一条 404 消息。如果我转到http://server/app/controller/action,我还会收到一条 404 消息。

【问题讨论】:

  • 可以访问 app 网络吗?尝试创建 index.html 并检查它是否以 server/app/index.html 的身份工作
  • 还可以查看您的虚拟主机文件。您可能需要为 url 创建一个配置文件。
  • 您的网站网址是什么??
  • jagad89,我创建了server/app/phpinfo.php,它工作正常。 abdulla,这是一个内网页面。
  • 您使用的是什么版本的codeigniter,如果您使用的是codeigniter 3.0,请检查所有控制器和模型首字母大写示例Welcome.php而不是 welcome.php 和模型 Model_something.php

标签: php wordpress .htaccess codeigniter mod-rewrite


【解决方案1】:

我有同样的问题。只需将文件权限更改为 644 到 index.php 当我通过 git 拉取更改时。权限更改为 664 所以改回 644。希望这能解决问题。

【讨论】:

    【解决方案2】:

    改变这个

    在你的config.php

    1. $config['base_url'] = '';
    2. $config['index_page'] = '';
    3. $config['uri_protocol'] = 'AUTO';

    然后在.htaccess(**这应该放在应用程序文件夹之外**)

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

    也请阅读本文

    1. Controllers
    2. Models
    3. Views

    【讨论】:

    • 你是否按照我所说的放置了 .htacess 文件??
    • 给我你的网址
    • 这解决了问题,但现在视图没有按预期加载。
    • 你能提供我你的网站网址吗??
    • 如果我的回答有帮助,请接受它或投票。谢谢
    【解决方案3】:

    已解决: 我刚刚发现控制器的文件必须有大写字母的名称。

    http://www.codeigniter.com/user_guide/general/controllers.html

    【讨论】:

      【解决方案4】:

      尝试删除 SetEnv 。您可以在 index.php 文件中设置环境。

      对于base_url,请确保它是index.php页面所在的文件夹级别。

      /app/ 应该包含应用程序文件夹。

      对于 index_page,我不会将其设置为空白。放回'index.php';

      在你的 htaccess 中试试这个,

       RewriteEngine on
       RewriteCond %{REQUEST_FILENAME} !-f
       RewriteCond %{REQUEST_FILENAME} !-d
      
       RewriteCond %{HTTP_HOST} ^yoursite.com [nc]
       RewriteRule ^(.*)$ http://www.yoursite.com/$1 [r=301,nc]
       RewriteCond $1 !^(index\.php|js|img|css|application|robots\.txt)
       RewriteRule ^(.*)$ /index.php/$1 [L]
      

      您可能不需要在 RewriteCond 中包含应用程序文件夹,但无论如何都要尝试。

      确保在 /config/routes.php 文件中设置了 default_contoller。

       $route['default_controller'] = "default_controller_here";
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-12-05
        • 2020-10-17
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-08-27
        • 2015-03-06
        相关资源
        最近更新 更多