.htaccess file not works in LAMP .htaccess file not works in LAMP codeigniter codeigniter

.htaccess file not works in LAMP


Open your terminalRun this following code:

sudo nano /etc/apache2/apache2.conf

go down and change:

AllowOverride All

look like:

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

Then restart apache2.

sudo service apache2 restart

and then .htaccess file is

RewriteEngine OnRewriteCond %{REQUEST_FILENAME} !-fRewriteCond %{REQUEST_FILENAME} !-dRewriteRule ^(.*)$ index.php/$1 [L]


You can't just move from one server to another and not make sure your prerequistes are there. These things are not on by default on most systems. You also have not given any specifics about your setup or even your document root.

So going off that it's an Ubuntu server and apache2, you need to do these things.

First thing you need to do if this is a new LAMP install is make sure rewrite is on.

Run this command to enable mod_rewrite.

sudo a2enmod rewrite

Then you need to make sure you allow .htaccess in your document root.

edit

/etc/apache2/sites-available/000-default.conf

In this file search for this

 AllowOverride None

and change it to

AllowOverride All

Then restart apache2.

sudo service apache2 restart

EDIT: Based on your comment, you need to make your vhost look like this and then restart apache2.

    <VirtualHost *:80>     ServerAdmin webmaster@localhost     DocumentRoot /var/www/html     ErrorLog ${APACHE_LOG_DIR}/error.log     CustomLog ${APACHE_LOG_DIR}/access.log combined     <Directory /var/www/html>      AllowOverride All    </Directory>    </VirtualHost>


Are you sure mod_rewrite module is loaded ? go to httpd.conf and search for -

LoadModule rewrite_module modules/mod_rewrite.so

and make sure theres no # [hash tag] before