Saturday, April 20, 2024
 Popular · Latest · Hot · Upcoming
3
rated 0 times [  3] [ 0]  / answers: 1 / hits: 3509  / 2 Years ago, sat, june 11, 2022, 6:43:00

This might not be directly related to Ubuntu itself, but the directory tree is different here and I'm kind of confused.



I have a website I'm trying to run and it loads fine, but it heavily relies on URL rewrites which I'm not getting because .htaccess directives might not be enabled in my installation. I've followed the article at Ubuntu.com to enable .htaccess files on my apache2, but I couldn't follow it because the files it tells me to change do not exist in the folder it tells me to go.



This is the closest file name to default - 000-default.conf:



<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
#ServerName www.example.com

ServerAdmin webmaster@localhost
DocumentRoot /var/www

# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn

ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined

# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
</VirtualHost>

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet


I don't see any <Directory /var/www/> block here.



How do I enable my .htaccess files? I need them per project basis.


More From » apache2

 Answers
6

Add to VirtualHost:



<VirtualHost *:80>
AccessFileName .htaccess (.htaccess is the default filename)
...
<Directory /var/www/>
Options Indexes FollowSymLinks Includes
AllowOverride All
Order allow,deny
Allow from all
</Directory>
...
</VirtualHost>


then restart apache:



service apache2 restart


To check if it works, add this line to .htaccess :



ErrorDocument 404 /error404.html


for error 404 (page not found) your browse should open your custom error page, in this case error404.html


[#26111] Sunday, June 12, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
oraoming

Total Points: 354
Total Questions: 105
Total Answers: 124

Location: Iraq
Member since Sat, Apr 3, 2021
3 Years ago
oraoming questions
Fri, Aug 20, 21, 10:08, 3 Years ago
Mon, May 24, 21, 21:56, 3 Years ago
Mon, Dec 12, 22, 23:21, 1 Year ago
Mon, Sep 12, 22, 11:38, 2 Years ago
;