File tree Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Original file line number Diff line number Diff line change @@ -160,6 +160,39 @@ The following converters exist:
160
160
`path ` like the default but also accepts slashes
161
161
=========== ===========================================
162
162
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
+
163
196
.. _url-building :
164
197
165
198
URL Building
You can’t perform that action at this time.
0 commit comments