If you want to try it out, I have pushed up new feature to allow rewrite rules.
Currently on develop branch of mod_wsgi Git repo.
pip install -U
https://github.com/GrahamDumpleton/mod_wsgi/archive/develop.zip
<https://github.com/GrahamDumpleton/mod_wsgi/archive/develop.zip>
The rewrite rules can be placed in the rewrite.conf file in the server root
directory.
Better still, use the —rewrite-rules option to specify the location of your own
file containing the rewrite rules.
For example:
$ mod_wsgi-express start-server tests/envirowsgi --rewrite-rules rewrite.conf
--log-level 'info rewrite:trace8' --log-to-terminal
Server URL : http://localhost:8000/
Server Root : /tmp/mod_wsgi-localhost:8000:502
Server Conf : /tmp/mod_wsgi-localhost:8000:502/httpd.conf
Error Log File : /dev/stderr (info rewrite:trace8)
Rewrite Rules : /Users/graham/Projects/mod_wsgi/rewrite.conf
Request Capacity : 5 (1 process * 5 threads)
Request Timeout : 60 (seconds)
Queue Backlog : 100 (connections)
Queue Timeout : 45 (seconds)
Server Capacity : 20 (event/worker), 20 (prefork)
Server Backlog : 500 (connections)
Locale Setting : en_AU.UTF-8
You don’t need a RewriteEngine On directive.
Just include your RewriteCond/RewriteRule directives.
Avoid using RewriteBase as may well screw up what mod_wsgi rules do and not
sure it is needed anyway in that context.
The rules should be applied before static file matching, so can also be used to
remap static files as well.
A really simple example of a rewrite.conf file would be:
RewriteRule ^/?$ /blah [R=301]
This would cause access to root of site using just ‘/‘ to be redirected to
‘/blah’. Everything else should flow through as normal.
If you find any issues or have problems constructing the rules you want then
let me know.
Graham
> On 13 Jan 2016, at 9:42 AM, Graham Dumpleton <[email protected]>
> wrote:
>
>
>> On 13 Jan 2016, at 9:23 AM, Graham Dumpleton <[email protected]
>> <mailto:[email protected]>> wrote:
>>
>>>
>>> On 13 Jan 2016, at 4:14 AM, Gavin Cannizzaro <[email protected]
>>> <mailto:[email protected]>> wrote:
>>>
>>> Hi all,
>>>
>>> I love mod_wsgi-express. As someone relatively new to Linux, Apache,
>>> Python, and WSGI, "express" works as advertised by getting me up and
>>> running. I'm already using it in production.
>>>
>>> When I use a rewrite rule in the custom configuration, though, it is
>>> completely ignored.
>>>
>>> My test case is just a few lines, calling mod_wsgi-express with a standard
>>> test script, a port number, a document-root, and an included config.
>>>
>>> The included config has just
>>>
>>> RewriteEngine On
>>> RewriteRule ^ /blah [R=301]
>>>
>>> (I don't actually want redirects, but it's a stronger test.)
>>>
>>> In any case, I don't see the rule being picked up. I know that I have
>>> mod_rewrite enabled, and it works in a regular Apache site. And even with
>>> express, I'm sure that the module is loaded, based on an IfModule rule that
>>> sets a header.
>>>
>>> Is this supposed to be supported with express? Does it need to be used in
>>> conjunction with some other configuration? I've seen Graham suggest
>>> rewrite rules in reference to various issues, but not specifically where
>>> "express" is involved.
>>
>> Unfortunately it isn’t that simple. Because mod_wsgi-express uses rewrite
>> rules to allow the WSGI application to overlay a static document root,
>> adding rewrite rules at the end of the configuration file at top level will
>> not be recognised, or if put inside of a Location directive will usually
>> screw things up. Any rewrite rules likely need to be supplied separately
>> with an option used to point at the rewrite file. The rules would then need
>> to be included in a particular location within the generated configuration
>> just after the rewrite rules mod_wsgi uses. Even then there may be
>> complications or rules would need to be written a certain way.
>>
>> The alternative for simple redirect rules is to use the redirect directives
>> from mod_alias.
>>
>> https://httpd.apache.org/docs/2.4/mod/mod_alias.html
>> <https://httpd.apache.org/docs/2.4/mod/mod_alias.html>
>>
>> You can thus quite happily use something like:
>>
>> Redirect /dog /cat
>> RedirectMatch ^/?$ /index
>>
>> For more complicated rewrite rules, would need to see what exactly you are
>> trying to do.
>>
>> I will though have a quick try at adding a —rewrite-rules option and include
>> it at where I think they need to be and see what is possible.
>>
>> BTW, if using Apache 2.4, it is very easy to enable rewrite trace logs by
>> doing:
>>
>> mod_wsgi-express start-server tests/environ.wsgi --include-file
>> redirect.conf --log-level 'info rewrite:trace8' --log-to-terminal
>>
>> That is, use —log-level with quoted option ‘info rewrite:trace8’.
>>
>> That way you can see whether rewrite rules are applied at all, what they are
>> being given and what it generates.
>
> A quick test of hacking into the generated configuration file:
>
> <Directory '/tmp/mod_wsgi-localhost:8000:502/htdocs/'>
> <IfDefine MOD_WSGI_DIRECTORY_INDEX>
> DirectoryIndex None
> </IfDefine>
> <IfDefine MOD_WSGI_DIRECTORY_LISTING>
> Options +Indexes
> </IfDefine>
> <IfDefine MOD_WSGI_CGI_SCRIPT>
> Options +ExecCGI
> </IfDefine>
> <IfDefine MOD_WSGI_CGID_SCRIPT>
> Options +ExecCGI
> </IfDefine>
> <IfDefine !MOD_WSGI_STATIC_ONLY>
> RewriteEngine On
> Include /Users/graham/Projects/mod_wsgi/rewrite.conf
> RewriteCond %{REQUEST_FILENAME} !-f
> <IfDefine MOD_WSGI_DIRECTORY_INDEX>
> RewriteCond %{REQUEST_FILENAME} !-d
> </IfDefine>
> <IfDefine MOD_WSGI_SERVER_STATUS>
> RewriteCond %{REQUEST_URI} !/server-status
> </IfDefine>
> RewriteRule .* - [H=wsgi-handler]
> </IfDefine>
> Order allow,deny
> Allow from all
> </Directory>
>
> and then having in rewrite.conf:
>
> RewriteRule ^/?$ /blah [R=301]
>
> does appear to work.
>
> BTW, another way might have been to use in the include configuration file:
>
> <Directory /some/path/to/document/root>
> AllowOverride FileInfo
> </Directory>
>
> then add a .htaccess file to the document directory and add rewrite rules in
> there.
>
> Rewrite rules in .htaccess files are fiddly to get right though and does look
> a bit like they trying to add them there also stuffs up the mod_wsgi rewrite
> rules as no longer falls through to WSGI application and get not found
> instead.
>
> Graham
>
--
You received this message because you are subscribed to the Google Groups
"modwsgi" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/modwsgi.
For more options, visit https://groups.google.com/d/optout.