: Apache: redirect URL of internal WSGI server The following Apache conf file serves a WSGI application via port 9002: <VirtualHost *:9002> SSLEngine on SSLCertificateFile /etc/apache2/ssl/apache.crt
The following Apache conf file serves a WSGI application via port 9002:
<VirtualHost *:9002>
SSLEngine on
SSLCertificateFile /etc/apache2/ssl/apache.crt
SSLCertificateKeyFile /etc/apache2/ssl/apache.key
WSGIDaemonProcess matching-server user=ubuntu group=ubuntu threads=1
WSGIScriptAlias / /var/www/matching-server/server.wsgi
<Directory /var/www/matching-server>
WSGIProcessGroup matching-server
WSGIApplicationGroup %{GLOBAL}
AllowOverride AuthConfig
Order deny,allow
Allow from all
</Directory>
</VirtualHost>
The WSGI server responds to /metadata call, and returns a JSON with uptime information. I would like to alias /api to /metadata, so that calls to /api will be re-written as calls to /metadata and sent to the internal WSGI server.
I have enabled mod_rewrite on the Ubuntu server:
sudo a2enmod rewrite
And added the following rewrite rule to the conf file:
RewriteEngine On
RewriteRule ^api/?$ /metadata [NC,L]
I tried adding the rewrite rule after the SSL section and inside the Directory section, but I am still getting a Not Found error when accessing /api:
Not Found
The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again.
Needless to mention, /metadata works without problems with or without the redirect rule.
Any idea what's wrong with my rewrite rule?
More posts by @Michele947
1 Comments
Sorted by latest first Latest Oldest Best
I needed a PT flag instead of [NC, L] in order to pass the result URL to WSGIScriptAlias:
RewriteEngine On
RewriteRule ^/api$ /metadata [PT]
Quoting the manual:
The target (or substitution string) in a RewriteRule is assumed to be
a file path, by default. The use of the [PT] flag causes it to be
treated as a URI instead. That is to say, the use of the [PT] flag
causes the result of the RewriteRule to be passed back through URL
mapping, so that location-based mappings, such as Alias, Redirect, or
ScriptAlias, for example, might have a chance to take effect.
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2025 All Rights reserved.