To get Directus working on most servers all you need to do is ensure that traffic is routed to the correct files. Let's take a look at some common examples below.
The mod_rewrite
is an Apache module that uses a ruled-based rewriting engine to rewrite requested URLs.
Directus API requires mod_rewrite
to be enabled on Apache, because it uses the URL rewriting to maps all requested URLs to an internal endpoint unless it matches an actual file in the filesystem.
The rewrite rules are include in Directus API inside the public
directory in a .htaccess
file that serve as the front controller for all the endpoints.
Apache include mod_rewrite
by default. If that's not the case, how to install it will depends on your system and apache version, and the best option will be to go to the Compiling and Installing section on Apache and tries to compile and install mod_rewrite
individually.
Apache has a tool called apxs
(APache eXtenSion) for lets you build and install modules this is a good option to install new modules from source.
There's different way to enable a module after being installed. On ubuntu-based distribution can be enabled using a2enmod
script.
a2enmod rewrite
Make sure to reload all apache configuration.
service apache2 reload
If you are not using a ubuntu-based distribution or a2enmod
is not available in your system, you can go to your apache configuration, on ubuntu-based system are usually located in /etc/apache2/conf/httpd.conf
, and add a line to load the rewrite module.
LoadModule rewrite_module modules/mod_rewrite.so
rewrite_module
is the module name and modules/mod_rewrite.so
is the path where the module file is located. In this case the module file is relative to the ServerRoot
configured in your httpd.conf
Using the command line you can execute: apachectl -M | grep 'rewrite'
and it will filter all installed modules that matches rewrite
, if rewrite_module
is returned, congratulations you already have installed and enabled mod_rewrite
in your system.
Directus API comes with .htaccess
files for the required configuration. These .htaccess
won't work until the AllowOverride
directive is set within a Directory block.
<Directory>
block that points to Directus API rootAllowOverride All
inside the <Directory>
block to allow all directives in .htaccess
including the mod_rewrite
directives.TIP
Directus .htaccess
actually uses FileInfo
for rewriting and Options
to following symlinks
<VirtualHost *:80>
ServerAdmin admin@example.com
ServerName example.com
ServerAlias www.example.com
DocumentRoot /var/www/directus/public
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory /var/www/directus>
AllowOverride All
</Directory>
</VirtualHost>
TIP
.htaccess
is the default filename for the AccessFileName
directive.
directus.conf
disable_symlinks if_not_owner;
location /admin {
rewrite ^/admin/(.*) /admin/index.html last;
}
location / {
try_files $uri $uri/ /index.php$args;
}
location /thumbnail {
rewrite /thumbnail/(.*) /thumbnail/index.php last;
}
# Deny direct access to php files in extensions
location /extensions/.+\.php$ {
deny all;
}
# All uploads files (originals) cached for a year
location ~* /uploads/([^/]+)/originals/(.*) {
add_header Cache-Control "max-age=31536000";
}
# Serve php, html and cgi files as text file
location ~* /uploads/.*\.(php|phps|php5|htm|shtml|xhtml|cgi.+)?$ {
add_header Content-Type text/plain;
}
# Deny access to any file starting with .ht,
# including .htaccess and .htpasswd
location ~ /\.ht {
deny all;
}
Coming soon.