How to enable use of .htaccess in Apache on Ubuntu?
Solution 1
First Step
Open file as
sudo vim /etc/apache2/apache2.conf
Second Step
remove comment sign (#) if you find it before this line ( line number 187 approx.)
AccessFileName .htaccess
Third Step
Then find the line where there is
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
replace "None" with "All"
AllowOverride All
And voila... .htaccess
works!!
Solution 2
Activate ModRewrite:
sudo a2enmod rewrite
sudo /etc/init.d/apache2 restart
Solution 3
In my case the changing AllowOverride None
to AllowOverride All
in
/etc/apache2/sites-enabled/000-default.conf helped.
All other .conf files have already had AllowOverride All
.
Solution 4
- In /etc/apache2/apache2.conf remove comment sign (
#
) fromAccessFileName .htaccess
The name of your Apache configuration file is not standard. You can rename it to default.conf in Windows and rename it to default in Linux. In Linux based OS run this code in terminal:
sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/default
Related videos on Youtube
David ZIP
Updated on September 18, 2022Comments
-
David ZIP over 1 year
I'm trying to enable use of htaccess file in Ubuntu 14.04 (Apache 2.4.7). I know that this question has many possible duplicates, but none of them helped me yet.
.htaccess
ErrorDocument 404 /404.html
000-default.conf
<VirtualHost *:80> AccessFileName .htaccess ServerAdmin webmaster@localhost DocumentRoot /var/www ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined <Directory /var/www/> Options Indexes FollowSymLinks Includes AllowOverride All Order allow,deny Allow from all </Directory> </VirtualHost>
What else is needed?
-
closetnoc about 10 yearsThe AllowOverride All directive allows all options in the .htaccess file. The 000-default.conf assumes that there is only one site on your server. Is the .htaccess file not working for you? Are there more than one site hosted on this server?
-
David ZIP about 10 yearsThere are many folders in /var/www but no virtual hosts are created. /etc/apache2/sites-available/ folder contains two files, 000-default.conf and default-ssl.conf. htaccess file is located in /var/www/
-
Kevin Woblick about 10 yearsMaybe 'DocumentRoot /var/www/'? (trailing slash)
-
Stephen Ostermiller about 10 yearsCheck to make sure /etc/apache2/sites-enabled/ contains a link to 000-default.conf. If you change the /var/www/index.html file you can see the changes when you view the server with a web browser, right?
-
-
Stephen Ostermiller about 10 yearsIt is named with the zeros so that it comes first alphabetically. If you have a default.conf file and then create a site for anteater.com, then anteater becomes the default host because it gets loaded first. Keep the 000 to prevent such problems. The name of the conf file shouldn't have anything to do with whether or not .htaccess works.
-
David ZIP about 10 years'AccessFileName .htaccess' is already uncommented. Above answer helped me. Thanks.
-
Stephen Ostermiller over 9 yearsThe
service
command is now the preferred way to restart Apache:sudo service apache2 restart
. -
Tahir Yasin over 9 yearschanges didn't take effect until I restarted apache Command: service apache restart
-
www139 over 7 yearsI suggest, as @TahirYasin mentions, restarting apache.
sudo service apache2 restart
.