Foyaz Ullah Shahin
Foyaz Ullah Shahin

Reputation: 424

.htaccess file not works in LAMP

This is my .htaccess file. I am used Codeigniter Framework for my project.

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /project_name/
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>

Where is my mistake here? But It Works in xampp.

Upvotes: 2

Views: 6163

Answers (3)

Anowar Hossain
Anowar Hossain

Reputation: 581

Open your terminal Run 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 On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

Upvotes: 2

Gal Sisso
Gal Sisso

Reputation: 1959

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

Upvotes: 1

Panama Jack
Panama Jack

Reputation: 24478

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>

Upvotes: 4

Related Questions