how to config htaccess file after enabling mod_rewrite module?
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
Related videos on Youtube
jazz_razor
Updated on September 18, 2022Comments
-
jazz_razor over 1 year
I already install
apache2
then i enable themod_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 indafault.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:
here is the screen shot of 403 forbidden error:
-
jazz_razor over 9 yearscant find above line in default.conf
-
jazz_razor over 9 yearsnot worked. help me
-
muru over 9 years@jazz_razor You are supposed to add these lines, above the line with
</VirtualHost>
. -
jazz_razor over 9 yearsi added these lines but it still giving me 403 forbidden error
-
jazz_razor over 9 yearsi am working in this directory /var/www/html/my_project
-
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 over 9 yearsyes 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 over 9 years@jazz_razor yes, but are the permissions proper for Apache? Can the server read those files?
-
jazz_razor over 9 yearsyes server can read those files.
-
jazz_razor over 9 yearsif 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 over 9 years@jazz_razor Did you restart apache after you did the modifications to the
000-default.conf
file? You can restart it withsudo apache2ctl restart
. If you did, are you sure the rewrite rules are correct? -
jazz_razor over 9 yearsyes i restart the apache and my rewirte rules are correct because website is running live.
-
Adam F over 8 yearsIt worked for me, dang updated ubuntu distros >.>
-
Ramesh Chand about 8 yearsFor security reason, other users may only read your .htaccess, you should use sudo chmod 644 /var/www/html/.htaccess to update permissions.