PHP - 代码点火器 URL 在没有 index.object 的情况下不起作用


PHP - codeigniter URL not working without index.object not found

我正在为我的网站使用 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>

这是我的data_controller:

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。

非常感谢您的帮助!

尝试以下操作

打开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] 

希望有帮助.

在 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]

配置.php

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

所有方法都记住,您应该将文件名和类的第一个字母大写,其余为小写。

更多 htaccess 示例,请点击此处

注意:我在 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。

请尝试在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] 

在您的 .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>

有关更多详细信息,您可以访问此处