> On 13 Jan 2016, at 9:23 AM, Graham Dumpleton <[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.

Reply via email to