简体   繁体   中英

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

I am using codeigniter v3 for my website and I'm having problems redirecting from one page to another.

If I click the tab, the link shows localhost:8080/IDS/view/decisiontree and shows Object not found! The requested URL was not found on this server... Object not found! The requested URL was not found on this server...

If I edit the URL and make it localhost:8080/IDS/index.php/view/decisiontree , the site perfectly loads.

Here are my routes:

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

Here are the codes of the tab related:

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

Here is my data_controller:

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

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

And here is my config.php :

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

Here's my .htaccess:

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

And note, I'm using Codeigniter V3.

Thanks a lot for the help!

Try the following

Open config.php and do following replaces

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

to

$config['index_page'] = ""

In some cases the default setting for uri_protocol does not work properly. Just replace

$config['uri_protocol'] ="AUTO"

by

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

Hope it helps .

Try this htaccess in main directory of your codeIgniter project. It seems to work fine in xampp and 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';

All ways remember that you should have first letter of file name and class as upper case the rest lower case. refer

More htaccess examples here

Note: I'm on Ubuntu, so the paths here may change if you are on another distro.

I tried all .htaccess suggestions and none seemed to work, so I started thinking that was not the problem. And then it hit me, the apache.conf file. Doesn't matter the .htaccess you have, if that file is restricting the override, there's nothing you can do.

So i went to /etc/apache2/ and edited the apache2.conf file adding this:

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

Also change $config['index_page'] = index; to $config['index_page'] = ''; in application/config/config.php as said above.

Btw, my .htaccess looks like this:

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

And don't forget to restart apache.

Please try to set the index_page blank in config.php file

$config['index_page']= "";

Also please change the .htaccess file:

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

Try below in your .htaccess file

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

For more detail, you can visit here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM