【问题标题】:404 page not found issue arise when htaccess change in codeigniter当 codeigniter 中的 htaccess 更改时出现 404 页面未找到问题
【发布时间】:2014-05-29 21:58:58
【问题描述】:

ht访问代码:

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

配置文件:

$config['base_url'] = 'http://baseurl/apps';
    $config['index_page'] = '';
    $config['uri_protocol'] = 'AUTO';
    $config['enable_hooks'] = FALSE;
    $config['allow_get_array']      = TRUE;
    $config['enable_query_strings'] = FALSE;

我收到“404 page not found”错误。 当我更改 htaccess 文件时

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

出现“没有指定输入文件”错误。

我已经尝试了几个 htaccess 代码,但我仍然遇到这些问题。

我正在使用上面的 htaccess 代码,用于从 url 中删除 index.php。

【问题讨论】:

  • 您运行的是哪种网络服务器? IIS、Apache 等

标签: php .htaccess codeigniter


【解决方案1】:

尝试设置

RewriteBase /apps/

在您的 .htaccess 文件中

总的来说,我使用这个 htaccess,它从来没有让我失望:

     <IfModule mod_rewrite.c>
        RewriteEngine On
        RewriteBase /

        #Removes access to the system folder by users.
        #Additionally this will allow you to create a System.php controller,
        #previously this would not have been possible.
        #'system' can be replaced if you have renamed your system folder.
        RewriteCond %{REQUEST_URI} ^system.*
        RewriteRule ^(.*)$ /index.php?/$1 [L]

        #When your application folder isn't in the system folder
        #This snippet prevents user access to the application folder
        #Submitted by: Fabdrol
        #Rename 'application' to your applications folder name.
        RewriteCond %{REQUEST_URI} ^application.*
        RewriteRule ^(.*)$ /index.php?/$1 [L]

        #Checks to see if the user is attempting to access a valid file,
        #such as an image or css document, if this isn't true it sends the
        #request to index.php
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteRule ^(.*)$ index.php?/$1 [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.
        # Submitted by: ElliotHaughin

        ErrorDocument 404 /index.php
    </IfModule>

【讨论】:

  • @Dexa:谢谢。我在 htaccess 文件中添加了 RewriteBase /apps/ 代码,它工作正常。
【解决方案2】:

还不能使用 cmets,所以我使用答案框。您可能想看看这个问题,该问题已得到解决,并且似乎与您的问题几乎完全相同:CodeIgniter htaccess and URL rewrite issues

编辑:如果您使用的是 nginx 或其他网络服务器,请记住这些服务器不支持 .htaccess 文件。我有时也会在某些应用程序的 nginx 中收到“未指定文件输入”错误。大多数情况下,因为这些服务器不支持 .htaccess 文件。所以,请确保您使用的是 Apache。

【讨论】:

  • 已经由@Dexa 发布,您可以尝试使用 RewriteBase,因为 index.php 位于根目录(应用程序)的文件夹下。还要检查你的配置 base_url,在那里你可以看到在 URL 下,是一个子文件夹 apps。否则 Apache 将在根目录 '/' 而不是 '/apps' 中查找它。希望这会有所帮助。
猜你喜欢
  • 2012-08-27
  • 2018-05-13
  • 1970-01-01
  • 1970-01-01
  • 2015-07-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-25
相关资源
最近更新 更多