Hi
What’s the difference between sites-available and sites-enabled?
I’m having some difficulty getting either .htaccess or mod_rewrite to work. I’m not sure which bit is failing at the moment.
I been reading two guides
‘How To Use the .htaccess File’ tells me to open /etc/apache2/**sites-available**/default which is empty (?), according to the guide it shouldn’t be.
And ‘How To Set Up mod_rewrite for Apache on Ubuntu 14.04’ tells me to open /etc/apache2/**sites-enabled**/000-default.conf
Am I supposed to be editing both these files?
Bit confused :)
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
I had a rough time with this earlier, and I can’t find the source of this information right now. I will keep looking, but…
To enable .htaccess to your web directory on Ubuntu 16.04, the file you need to edit is located at:
/etc/apache2/apache2.conf
Towards the middle/lower end of the file you will see:
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
If you have AllowOverride None, change it to AllowOverride All
This turns on .htaccess for your web directory.
From here you should be able to follow the instructions for Enabling mod_rewrite from here: https://www.digitalocean.com/community/tutorials/how-to-set-up-mod_rewrite-for-apache-on-ubuntu-14-04
Which should be as follows:
sudo a2enmod rewrite
sudo systemctl restart apache2
Mine was already enabled I believe.
Thanks for the replies!
This is the contents of my /etc/apache2/apache2.conf
I can’t see the lines @JasonLabs mentions?
Should I just add them?
# This is the main Apache server configuration file. It contains the
# configuration directives that give the server its instructions.
# See http://httpd.apache.org/docs/2.4/ for detailed information about
# the directives and /usr/share/doc/apache2/README.Debian about Debian specific
# hints.
#
#
# Summary of how the Apache 2 configuration works in Debian:
# The Apache 2 web server configuration in Debian is quite different to
# upstream's suggested way to configure the web server. This is because Debian's
# default Apache2 installation attempts to make adding and removing modules,
# virtual hosts, and extra configuration directives as flexible as possible, in
# order to make automating the changes and administering the server as easy as
# possible.
# It is split into several files forming the configuration hierarchy outlined
# below, all located in the /etc/apache2/ directory:
#
# /etc/apache2/
# |-- apache2.conf
# | `-- ports.conf
# |-- mods-enabled
# | |-- *.load
# | `-- *.conf
# |-- conf-enabled
# | `-- *.conf
# `-- sites-enabled
# `-- *.conf
#
#
# * apache2.conf is the main configuration file (this file). It puts the pieces
# together by including all remaining configuration files when starting up the
# web server.
#
# * ports.conf is always included from the main configuration file. It is
# supposed to determine listening ports for incoming connections which can be
# customized anytime.
#
# * Configuration files in the mods-enabled/, conf-enabled/ and sites-enabled/
# directories contain particular configuration snippets which manage modules,
# global configuration fragments, or virtual host configurations,
# respectively.
#
# They are activated by symlinking available configuration files from their
# respective *-available/ counterparts. These should be managed by using our
# helpers a2enmod/a2dismod, a2ensite/a2dissite and a2enconf/a2disconf. See
# their respective man pages for detailed information.
#
# * The binary is called apache2. Due to the use of environment variables, in
# the default configuration, apache2 needs to be started/stopped with
# /etc/init.d/apache2 or apache2ctl. Calling /usr/bin/apache2 directly will not
# work with the default configuration.
# Global configuration
#
#
# ServerRoot: The top of the directory tree under which the server's
# configuration, error, and log files are kept.
#
# NOTE! If you intend to place this on an NFS (or otherwise network)
Ok, I’m not 100% sure how it works, but I’ve been able to get Step 4 — Setting Up Files from the guide working.
I’ll have to come back to this when I setup another Droplet, so I know exactly what I’m doing :)
This test rewrite works
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^about-test$ about-test.html [NC]
</IfModule>
If I visit example.com/about-test it shows the content of about-test.html and the url doesn’t have the .html extension.
So at least I know mod_rewrite and my .htaccess file is working…
That said, a set of rewrite rules I use on other hosting setups (that work fine) aren’t working…
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.