Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

325
Views
How do I configure my Apache Alias directive to capture all paths except two?

I'm using Apache 2 on Linux 18.04 with Python 3.6. I have the following virtual host set up ...

<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 lab.chicommons.coop

    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/html

    # 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

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

        Alias / /var/www/html/client/build/
        #<Directory /srv/rdmo/rdmo-app/static_root/>
        #    Require all granted
        #</Directory>
    # 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

        WSGIDaemonProcess maps \
            home=/var/www/html/web python-home=/var/www/html/web/venv
        WSGIProcessGroup maps 
        WSGIScriptAlias /coops /var/www/html/web/maps/wsgi.py/coops process-group=maps
        WSGIScriptAlias /data /var/www/html/web/maps/wsgi.py/data process-group=maps
        WSGIPassAuthorization On

        <Directory /var/www/html/web/maps>
            <Files wsgi.py>
                Require all granted
            </Files>
        </Directory>
</VirtualHost>

As you can see, this directive

Alias / /var/www/html/client/build/

captures all paths. However, I would like to set it up such that it captures all paths except "/coops*" and "/data*". How would I configure my Alias such that this is possible?

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

It's better to use Django's urls with regex to "catch" the urls. Define a url for "/coops*", a url for "/data*", and then a default url for anything else. If you want the web server to serve files directly from specific urls and not from Django, define them in <Directory...>.

Configure Apache according to this documentation. For example:

Alias /robots.txt /path/to/mysite.com/static/robots.txt
Alias /favicon.ico /path/to/mysite.com/static/favicon.ico

Alias /media/ /path/to/mysite.com/media/
Alias /static/ /path/to/mysite.com/static/

<Directory /path/to/mysite.com/static>
Require all granted
</Directory>

<Directory /path/to/mysite.com/media>
Require all granted
</Directory>

WSGIScriptAlias / /path/to/mysite.com/mysite/wsgi.py

<Directory /path/to/mysite.com/mysite>
<Files wsgi.py>
Require all granted
</Files>
</Directory>

If you have urls which you want to run specific views, define them as urlpatterns (documentation). And then, define a default view which you define as the last urlpattern to "catch" any url which was not caught by a specific view, and allocate it to a default view. You can also redirect it to a specific view, for example the main page. Or, you can keep your website without a default view, and then any url which doesn't match any view will return 404, which you can also customize if you want to.

over 4 years ago · Santiago Trujillo Report

0

It would get unruly with many more exceptions, but you can use PCRE's negative lookaheads easily here inside AliasMatch:

AliasMatch ^/(?!coops/)(?!data/).* /var/www/html/client/build/$0
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!