how to config htaccess file after enabling mod_rewrite module?

23,264

Solution 1

Edit /etc/apache2/apache2.conf instead of /etc/apache2/sites-available/ and edit as instructed.

Here's mine:

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

Solution 2

Firstly, in Ubuntu 14.04 (and Apache 2.4) the default DocumentRoot was changed from /var/www to /var/www/html. Secondly, the configuration was considerably simplified, so those entries, while usually present by default, no longer appear in the new default site configuration.

Edit /etc/apache/sites-enabled/default.conf, and add these lines:

<Directory /var/www/html>
    AllowOverride All
</Directory>

Your 403 Forbidden error is possibly because you are working in /var/www where you should be working in /var/www/html.

Finally, you shouldn't be enabling All, but pick out the options you need and enable only those.

Solution 3

Ubuntu 14.04 (and Apache 2.4) the default DocumentRoot was changed from /var/www to /var/www/html.

sudo nano /etc/apache2/sites-enabled/000-default.conf

add these lines at end

<Directory /var/www/html> AllowOverride All </Directory>

and of course >

sudo service apache2 restart

Share:
23,264

Related videos on Youtube

jazz_razor
Author by

jazz_razor

Updated on September 18, 2022

Comments

  • jazz_razor
    jazz_razor over 1 year

    I already install apache2 then i enable the mod_rewrite module like this:

    sudo a2enmod rewrite
    

    after enabling i am confused about these lines, i can't understand what to do with them, as far as i know that what i have to do with these lines is that " find the following section, and change the line that says AllowOverride from None to All. "

    <Directory /var/www/>
                    Options Indexes FollowSymLinks MultiViews
                    AllowOverride All
                    Order allow,deny
                    allow from all
    </Directory>
    

    my problem is that I can't find a file with the above lines to edit. I already looked in /etc/apache2/sites-available/. In that directory, I only found two files:

    000-default.conf 
    default-ssl.conf 
    

    In both files i can't find above lines which i have to edit.

    i edit the file /etc/apache2/apache2.conf in this directory but it still didn't worked at all.

    i also looked in this /etc/apache/sites-enabled/default.conf directory but i can't find these lines in dafault.conf

    <Directory /var/www/html>
        AllowOverride All
    </Directory>
    

    i am working in /var/www/html directory then why it's giving me 403 forbidden error.

    Still .htaccess is not running. It's giving me 403 forbidden error.

    here is the screen shot of folder permission:

    enter image description here

    here is the screen shot of 403 forbidden error: enter image description here

  • jazz_razor
    jazz_razor over 9 years
    cant find above line in default.conf
  • jazz_razor
    jazz_razor over 9 years
    not worked. help me
  • muru
    muru over 9 years
    @jazz_razor You are supposed to add these lines, above the line with </VirtualHost>.
  • jazz_razor
    jazz_razor over 9 years
    i added these lines but it still giving me 403 forbidden error
  • jazz_razor
    jazz_razor over 9 years
    i am working in this directory /var/www/html/my_project
  • muru
    muru over 9 years
    @jazz_razor I doubt your 403 error has anything to do with htaccess configuration. Have you set permissions correctly?
  • jazz_razor
    jazz_razor over 9 years
    yes i set permissions correctly. in this /var/www/html/ directory i can create folders, files and i can perform delete, edit actions easily through editor..
  • muru
    muru over 9 years
    @jazz_razor yes, but are the permissions proper for Apache? Can the server read those files?
  • jazz_razor
    jazz_razor over 9 years
    yes server can read those files.
  • jazz_razor
    jazz_razor over 9 years
    if i change the pattern of url like this: http://192.168.1.2/test.php it runs the php code but when i switch url like this: http://192.168.1.2/seocompany/ it gives me 403 forbidden error
  • Dan
    Dan over 9 years
    @jazz_razor Did you restart apache after you did the modifications to the 000-default.conf file? You can restart it with sudo apache2ctl restart. If you did, are you sure the rewrite rules are correct?
  • jazz_razor
    jazz_razor over 9 years
    yes i restart the apache and my rewirte rules are correct because website is running live.
  • Adam F
    Adam F over 8 years
    It worked for me, dang updated ubuntu distros >.>
  • Ramesh Chand
    Ramesh Chand about 8 years
    For security reason, other users may only read your .htaccess, you should use sudo chmod 644 /var/www/html/.htaccess to update permissions.