: Serving Static Files (such as js, css and images)

Serving Static Files (such as js, css and images)

Other languages : français


How to serve static files?

Solution server

Create a directory (also known as a folder) called static in the location of the script that runs the server. Then place the static files you wish to serve in the static folder.

For example, the URL http://localhost/static/logo.png will send the image ./static/logo.png to the client.


To serve static files with Apache an Alias directive can be used to map the request for a URL to a chosen directory, before it is handled by

Here is an example Virtual Host configured on a Unix like system with an Alias directive in effect:

<VirtualHost *:80>
    DocumentRoot /doc/root/
    # mounts your application if mod_wsgi is being used
    WSGIScriptAlias / /script/root/
    # the Alias directive
    Alias /static /doc/root/static
    <Directory />
        Order Allow,Deny
        Allow From All
        Options -Indexes
    # because Alias can be used to reference resources outside docroot, you
    # must reference the directory with an absolute path
    <Directory /doc/root/static>
        # directives to effect the static directory
        Options +Indexes