Php – How to set codeigniter for apache server

.htaccessapachecodeigniterphp

Updated,
I'm having some issues with deploying codeigniter project on Ubuntu server, i get 404 Apache error when i click on links.

When i put the project in http://roy.my-domain.com/ = /var/www/html/ folder – it's all works fine – but when i added sub directory http://roy.my-domain.com/roy/ = /var/www/html/roy/ – i get 404 errors .

When my url is http://roy.my-domain.com/roy/index.php/about – i get codeigniter 404 error and not apache2.

The error :

Not Found

The requested URL /index.php was not found on this server.

Apache/2.4.18 (Ubuntu) Server at roy.my-domain.com Port 80

Here are my settings :

0 . Checked for rewrite mod in Apache – got "Module rewrite already enabled"

1 . My project is in /var/www/my-project/

2 . In contains the following :
application
system
public_html
index.php
.htaccess

  1. The .htaccess file :

    < IfModule mod_rewrite.c >
    RewriteEngine On
    RewriteBase /html/my-project/
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d

    # Rewrite all other URLs to index.php/URL
    RewriteRule ^(.*)$ index.php?url=$1 [PT,L]

    < /IfModule >
    < IfModule !mod_rewrite.c>
    ErrorDocument 404 index.php
    < /IfModule >

  2. The apache2.conf :

    < Directory /var/www/ >
    Options Indexes FollowSymLinks
    Require all granted
    < /Directory >

    < Directory /var/www/html/ >
    Options Indexes FollowSymLinks
    AllowOverride All
    Require all granted
    < /Directory >

  3. The config.php :

    $config['base_url'] = 'http://roy.my-domain/my-project/';
    $config['index_page'] = '';
    $config['uri_protocol'] = 'AUTO';

  4. The index.php :

    (don't work with ../system and ../application)
    $system_path = 'system';
    $application_folder = 'application';

  5. The controllers :

    (codeigniter default view) Welcome.php
    About_Controller.php

  6. The views:
    (codeigniter default view) welcome_message.php
    about.php

Locally – all works fine…Thanks

Best Solution

<Directory /var/www/>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride All
                Order allow,deny
                allow from all
 </Directory>   

.htaccess:

    RewriteEngine On
    RewriteBase /html/project/

    RewriteCond %{THE_REQUEST} \s/+(.*?)/{2,}([^\s]*)
    RewriteRule ^ %1/%2 [R=302,L,NE]

    RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+(.+?)/{2,}[?\s] [NC]
    RewriteRule ^ /%1/ [L,R=301]

    RewriteCond %{HTTP_HOST} !^www\. [NC]
    RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI}  [R=301,L]

    RewriteCond %{REQUEST_URI} system|application
    RewriteRule ^(.*)$ index.php?/$1 [L]

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?/$1 [L]

Try this configuration and don't forget to reload Apache.

Related Question