For the server part of Python's WSGI specification, not the application part, is the server not allowed to rewrite requests? I ask because I can't find any that do. As I understand it Nginx and Apache are generic so they will have a rewrite rule engine (and IIS). Why wouldn't a WSGI capable server have the same so that I do not have to use regex? Does PEP-333 not allow rewrites? Is rewriting not a Python way to do things?
-
What does a rewrite rule engine have to do with an web interfacing standard? A rewrite rule engine is an *application*. Write a WSGI app that does this. – Martijn Pieters Feb 01 '16 at 21:44
-
@MartijnPieters I know you are the expert on Python. But that does not make sense to me. The application is separate from the server. Python servers that allow WSGI applications do not seem to have Rewrite engines. I do not want to create a rewrite engine in the application. I only want to deal with the results like I would with mod_rewrite. I have no idea if it has anything to do with it or not. That is why I asked the very specfic question about it. – johnny Feb 01 '16 at 21:47
-
But why would this need to be part of the specification? URL rewriting is orthogonal to a standard that lets you plug in Python code into a web server. – Martijn Pieters Feb 01 '16 at 21:49
-
2The specification doesn't preclude it, it *just doesn't care* because that's not the job of the specification or a server implementing a WSGI container. – Martijn Pieters Feb 01 '16 at 21:50
-
@MartijnPieters I have no idea why it would or wouldn't. I was asking if it precluded it. It does not appear to do so, and perhaps doing it at the server is not the Pythonic way. – johnny Feb 01 '16 at 21:50
-
WSGI servers simply haven't offered the feature. There is nothing unpythonic about this if they did offer it. It just hasn't been part of their focus. – Martijn Pieters Feb 01 '16 at 21:56
1 Answers
How paths are handled is not part of the WSGI server responsibility. It passes on the request to the apps, transparently, and returns the response produced, equally transparently. That is what the standard describes.
URL rewriting is an extra service that a server could implement, but that has nothing to do with the WSGI standard. Apache does this with an optional module (mod_rewrite
). It is a popular feature so other servers have offered it too. But that doesn't mean that the WSGI standard needs to say anything about this, just as the HTTP standard doesn't describe URL rewriting.
If you need paths rewritten, you can easily do so in your WSGI app, or write WSGI middleware to do so. WSGI middleware looks just like a WSGI app to the server, and like a server to the next app.
Someone already wrote such middleware for you, see the WSGIRewrite project.

- 1,048,767
- 296
- 4,058
- 3,343
-
The answer then is it something that it typically done at the server level, but the application, which is different from the non-Python world who use Apache, IIS, or something else? – johnny Feb 01 '16 at 21:49
-
Apache is an application too. It is just a very rich and versatile applicition, with plugins. `mod_rewrite` is a plugin (middleware?) that offers that functionality. WSGI servers are also versatile, in that middleware can solve this same problem. – Martijn Pieters Feb 01 '16 at 21:52