Search This Blog

Friday, March 16, 2012

Enabling .htaccess file in Linux

Enabling .htaccess file

.htaccess file is a powerful file that can be used to control and customize a site server behavior without editing the core Apache module. By default, the .htaccess functionality is turned off and all instances of .htaccess files are completely ignored. The server will not even attempt to read .htaccess files in the filesystem.

To enable .htaccess file, open up the settings file that you have created earlier:

gksu gedit /etc/apache2/sites-available/default

Scroll down the file until you see the part "<Directory /home/user/public_html/>". Underneath that line of code, change AllowOverride None to AllowOverride All.

apache-allowoverride

Save and exit the file.

In case of local host you may found above section of code as follows:


Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
# Uncomment this directive is you want to see apache2's
# default start page (in /apache2-default) when you go to /
#RedirectMatch ^/$ /apache2-default/

Also, if you need to use rewrite rules you need to enable them first. You do that with the following command.

sudo a2enmod rewrite
Prior to running that command you may get an error similar to the following.
[Tue Apr 14 14:23:34 2009] [alert] [client 127.0.0.1] /var/www/wiki/.htaccess: Invalid command 'RewriteEngine', perhaps misspelled or defined by a module not included in the server configuration

Finally, don't forget to restart Apache.

sudo /etc/init.d/apache2 restart

No comments:

Post a Comment