【问题标题】:PHP - codeigniter URL not working without index.php - object not foundPHP - 没有 index.php,codeigniter URL 不起作用 - 找不到对象
【发布时间】:2016-06-19 22:16:56
【问题描述】:

我正在为我的网站使用 codeigniter v3,但在从一个页面重定向到另一个页面时遇到问题。

如果我点击选项卡,链接会显示localhost:8080/IDS/view/decisiontree 并显示Object not found! The requested URL was not found on this server...

如果我编辑 URL 并将其设为 localhost:8080/IDS/index.php/view/decisiontree,则该站点将完美加载。

这是我的路线:

$route['view/decisiontree'] = 'data_controller/goto_decisiontree';

以下是相关标签的代码:

<li><a href="<?php echo base_url();?>view/decisiontree">Decision Tree</a></li>

这是我的数据控制器:

public function goto_decisiontree(){
    $data['page'] = "2";

    $this->load->view('decisiontree_page', $data);
}

这是我的config.php

$config['base_url'] = 'http://localhost:8080/IDS';
$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';

这是我的 .htaccess:

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

请注意,我使用的是 Codeigniter V3。

非常感谢您的帮助!

【问题讨论】:

  • 只是在base url末尾的注释提出斜杠/$config['base_url'] = 'http://localhost:8080/IDS/';
  • 你使用的是 wamp 还是 xampp 等?

标签: php .htaccess codeigniter xampp


【解决方案1】:

试试下面的

打开config.php 并进行以下替换

$config['index_page'] = "index.php"

$config['index_page'] = ""

在某些情况下,uri_protocol 的默认设置无法正常工作。直接替换

$config['uri_protocol'] ="AUTO"

通过

$config['uri_protocol'] = "REQUEST_URI"

HTACCESS

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

希望对您有所帮助。

【讨论】:

    【解决方案2】:

    在你的 codeIgniter 项目的主目录中试试这个 htaccess。它似乎在 xampp 和 wamp 中运行良好。

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

    config.php

    $config['base_url'] = 'http://localhost:8080/IDS/';
    $config['index_page'] = "";
    $config['uri_protocol'] = 'REQUEST_URI';
    

    请记住,文件名和类的首字母应为大写,其余为小写。 refer

    更多 htaccess 示例here

    【讨论】:

      【解决方案3】:

      注意:我在 Ubuntu 上,所以如果你在另一个发行版上,这里的路径可能会改变。

      我尝试了所有 .htaccess 建议,但似乎没有一个有效,所以我开始认为这不是问题所在。然后它击中了我,apache.conf 文件。不管你有什么 .htaccess,如果那个文件限制了覆盖,你就无能为力了。

      所以我去了/etc/apache2/ 并编辑了apache2.conf 文件添加了这个:

      <Directory /var/www/html/your-project-folder>
          AllowOverride All
          Require all granted
      </Directory>
      

      如上所述,将application/config/config.php 中的$config['index_page'] = index; 更改为$config['index_page'] = '';

      顺便说一句,我的 .htaccess 看起来像这样:

      RewriteEngine On
      RewriteRule ^(application) - [F,L]
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteRule .* index.php/$0 [PT,L]
      

      别忘了重启 apache。

      【讨论】:

        【解决方案4】:

        请尝试在 config.php 文件中将 index_page 设置为空白

        $config['index_page']= "";

        另外请更改 .htaccess 文件:

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

        【讨论】:

          【解决方案5】:

          在您的 .htaccess 文件中尝试以下操作

          <IfModule mod_rewrite.c>
          # Turn on URL rewriting
          RewriteEngine On
          
          # If your website begins from a folder e.g localhost/my_project then 
          # you have to change it to: RewriteBase /my_project/
          # If your site begins from the root e.g. example.local/ then
          # let it as it is
          RewriteBase /
          
          # Protect application and system files from being viewed when the index.php is missing
          RewriteCond $1 ^(application|system|private|logs)
          
          # Rewrite to index.php/access_denied/URL
          RewriteRule ^(.*)$ index.php/access_denied/$1 [PT,L]
          
          # Allow these directories and files to be displayed directly:
          RewriteCond $1 ^(index\.php|robots\.txt|favicon\.ico|public|assets|css|js|images)
          
          # No rewriting
          RewriteRule ^(.*)$ - [PT,L]
          
          # Rewrite to index.php/URL
          RewriteRule ^(.*)$ index.php/$1 [PT,L]
          </IfModule>
          

          更多详情,您可以访问here

          【讨论】:

            猜你喜欢
            • 2012-01-17
            • 1970-01-01
            • 1970-01-01
            • 2020-02-10
            • 1970-01-01
            • 1970-01-01
            • 2014-08-12
            • 2013-12-29
            • 2019-01-14
            相关资源
            最近更新 更多