1

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.

1

2 Answers 2

3

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

Sign up to request clarification or add additional context in comments.

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.