简体   繁体   中英

codeigniter not working without index.php in url

I'm working with a codeigniter project and I am able to use codeigniter out of the box when I install it on a digital ocean ubuntu droplet. However, when I load this project I want to use, if index.php is not in the url, the project breaks and I see a 404 error: The requested URL was not found on this server.

There is a login page at domain.com/index.php/login Even when I login, it gets redirected to domain.com/dashboard without the index.php

This is my .htaccess:

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

This is my config.php:

$config['index_page'] = '';
$config['base_url'] = 'http://my_really_cool_domain.com';

Oddly enough, if I add /index.php/ to the base_url it works, but the CSS / javascript resources do not load. Not sure why I am facing this error.

You should apply changes as below :

Try to replace uri_protocol in config.php as it,

//find this `index_page`
$config['index_page'] = "index.php"
// replace with it
$config['index_page'] = ""


//find this `uri_protocol`
$config['uri_protocol'] ="AUTO" 
// replace with it
$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>

For more refrence

Check default.conf

On my site, I use /etc/apache2/sites-enabled/000-default.conf On your site it might be /default.conf

You need to add this line:

AllowOverride all

This is what my conf file looks like:

VirtualHost *:80>
<Directory /var/www/html>
                AuthType Basic
                AuthName "Restricted Content"
                AuthUserFile /etc/apache2/.htpasswd
                Require valid-user
                Options +ExecCGI
                DirectoryIndex index.php
                AllowOverride all
        </Directory>
        DocumentRoot /var/www/html

Then restart apache: sudo service apache2 restart

Missing question mark ? after index.php in .htaccess, so

 RewriteRule ^(.*)$ index.php/$1 [L,QSA]

This is Correct Way

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

In Linux hosting environment this is usually required.

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