Thursday, September 20, 2012

How to enable .htaccess

In general, you should never use .htaccess files unless you don't have access to the main server configuration file. .htaccess files should be used in a case where the content providers need to make configuration changes to the server on a per-directory basis, but do not have root access on the server system. In the event that the server administrator is not willing to make frequent configuration changes, it might be desirable to permit individual users to make these changes in .htaccess files for themselves."

To make .htaccess files work as expected, you need to edit this file:
    /etc/apache2/sites-available/default

To enable rewite mode on the configuration file, please do the followings.
    - Open /etc/apache2/sites-available/default in your favourite file exitor.
    - Look for the Directory section of the configuration file. Example:
    - Change AllowOverride None to AllowOverride All
    - Save this file and then reload Apache as follows: #service apache2 reload

To enable apache2 rewrite module, use the Linux command listed below:
    #sudo a2enmod rewrite

To activate the new configuration, you need to run the command listed below:
      #service apache2 restart

To verify whether the module is working fine or not, please use the command listed below and check whether the rewite module is on the list.
    #apache2ctl -M

Example configuration for .htaccess file.
    # Original
    # If you modify this file then change the above line to: # Modified
   
       RewriteEngine On
       # Certain hosts may require the following line.
       # If vanilla is in a subfolder then you need to specify it after the /.
       # (ex. You put Vanilla in /forum so change the next line to: RewriteBase /forum)
       # RewriteBase /
       RewriteCond %{REQUEST_FILENAME} !-d
       RewriteCond %{REQUEST_FILENAME} !-f
       RewriteRule ^(.*)$ index.php\?p=$1 [QSA,L]
   


To password-Protect a directory with .htaccess, please refer https://help.ubuntu.com/community/EnablingUseOfApacheHtaccessFiles