It's my first time i'm uploading codeigniter project to production and i'm getting error 404 from Apache server.
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
I've read every article for 2 days and didn't found a solution....
So here are my settings :
Checked for rewrite mod in Apache - got "Module rewrite already enabled" My project is in /var/www/roy/ so the url is roy.my-domain.com/roy
Apache2.conf
<Directory /var/www/html/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
AccessFileName .htaccess
.htaccess
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /roy/
RewriteRule ^([a-z0-9_-]+)\.html$ index.php/page/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|asset|robots\.txt)
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
config.php
$config['base_url'] = 'http://'.$_SERVER['HTTP_HOST'].'/roy/';
$config['index_page'] = '';
autoload.php (i'm using Twig)
$autoload['libraries'] = array('database','session','twig');
The controllers structure
name Login.php -
class Login extends CI_Controller
Create a site folder inside your html one. Then, put your roy site there. Then, I would do it this way:
1 - apache2/sites-enabled/roy.my-domain.com.conf
<VirtualHost roy.my-domain.com:80>
DocumentRoot /var/www/html/site
ServerName roy.my-domain.com
<Directory /var/www/html/site>
Options FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
2 - .htaccess
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|robots\.txt)
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
3 - If it's not development, it's never a good practice to use the $_SERVER['HTTP_HOST'] superglobal. Can be changed from the client side. Just use the right url.
After you're done all that, restart apache. In Ubuntu is: $ sudo service apache2 restart
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With