Skip to content

Commit 9d98ad5

Browse files
committed
Documented redirect behaviour. Fixes pallets#42
1 parent cc8332e commit 9d98ad5

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

docs/quickstart.rst

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,39 @@ The following converters exist:
160160
`path` like the default but also accepts slashes
161161
=========== ===========================================
162162

163+
.. admonition:: Unique URLs / Redirection Behaviour
164+
165+
Flask's URL rules are based on Werkzeug's routing module. The idea
166+
behind that module is to ensure nice looking and also unique URLs based
167+
on behaviour Apache and earlier servers coined.
168+
169+
Take these two rules::
170+
171+
@app.route('/projects/')
172+
def projects():
173+
pass
174+
175+
@app.route('/about')
176+
def about():
177+
pass
178+
179+
They look rather similar, the difference is the trailing slash in the
180+
URL *definition*. In the first case, the canonical URL for the
181+
`projects` endpoint has a trailing slash. It's similar to a folder in
182+
that sense. Accessing it without a trailing slash will cause Flask to
183+
redirect to the canonical URL with the trailing slash.
184+
185+
However in the second case the URL is defined without a slash so it
186+
behaves similar to a file and accessing the URL with a trailing slash
187+
will be a 404 error.
188+
189+
Why is this? This allows relative URLs to continue working if users
190+
access the page when they forget a trailing slash. This behaviour is
191+
also consistent with how Apache and other servers work. Also, the URLs
192+
will stay unique which helps search engines not indexing the same page
193+
twice.
194+
195+
163196
.. _url-building:
164197

165198
URL Building

0 commit comments

Comments
 (0)