Skip to content

Commit 983a92a

Browse files
committed
Update with decisions
1 parent 4280536 commit 983a92a

File tree

1 file changed

+77
-64
lines changed

1 file changed

+77
-64
lines changed

docs/dev/design/redirects.rst

+77-64
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ Non-goals
2323
having a clear use case for them.
2424
- Improve the performance of redirects.
2525
This can be discussed in an issue or pull request.
26+
Performance should be considered when implementing new improvements.
2627
- Allow importing redirects.
2728
We should push users to use our API instead.
2829
- Allow specifying redirects in the RTD config file.
@@ -43,8 +44,10 @@ Prefix redirect:
4344
They are basically the same as an exact redirect with a wildcard at the end.
4445
They are a shortcut for a redirect like:
4546

46-
- From: ``/prefix/$rest``
47-
To: ``/en/latest/``
47+
From:
48+
``/prefix/$rest``
49+
To:
50+
``/en/latest/``
4851

4952
Or maybe we could use a prefix redirect to replace the exact redirect with a wildcard?
5053

@@ -139,51 +142,14 @@ The following improvements will be applied to all types of redirects.
139142
- Allow to add a short description.
140143
It's useful to document why the redirect was created.
141144

142-
Allow matching query arguments
143-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
144-
145-
We can do this in two ways:
146-
147-
- At the DB level with some restrictions.
148-
If done at the DB level,
149-
we would need to have a different field
150-
with just the path, and other with the query arguments normalized and sorted.
151-
152-
For example, if we have a redirect with the value ``/foo?blue=1&yellow=2&red=3``,
153-
if would be normalized in the DB as ``/foo`` and ``blue=1&red=3&yellow=2``.
154-
This implies that the URL to be matched must have the exact same query arguments,
155-
it can't have more or less.
156-
157-
I believe the implementation described here is the same being used by Netlify,
158-
since they have that same restriction.
159-
160-
If the URL contains other parameters in addition to or instead of id, the request doesn't match that rule.
161-
162-
https://docs.netlify.com/routing/redirects/redirect-options/#query-parameters
163-
164-
- At the Python level.
165-
If done at the DB level,
166-
we would need to have a different field
167-
with just the path, and other with query arguments.
168-
169-
The matching of the path would be done at the DB level,
170-
and the matching of the query arguments would be done at the Python level.
171-
Here we can be more flexible, allowing any query arguments in the matched URL.
172-
173-
We had some performance problems in the past,
174-
but I believe it was mainly due to the use of regex instead of using string operations.
175-
And matching the path is still done at the DB level.
176-
We could limit the number of redirects that can be created with query arguments,
177-
or the number of redirects in general.
178-
179145
Don't run redirects on domains from pull request previews
180146
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
181147

182148
We currently run redirects on domains from pull request previews,
183149
this is a problem when moving a whole project to a new domain.
184150

185-
Do we have the need to run redirects on external domains?
186-
They are suppose to be temporary domains.
151+
We don't the need to run redirects on external domains, they
152+
should be treated as temporary domains.
187153

188154
Normalize paths with trailing slashes
189155
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -195,8 +161,10 @@ We can simplify this by normalizing the path before matching it.
195161

196162
For example:
197163

198-
- From: ``/page/``
199-
To: ``/new/page``
164+
From:
165+
``/page/``
166+
To:
167+
``/new/page``
200168

201169
The from path will be normalized to ``/page``,
202170
and the filename to match will also be normalized before matching it.
@@ -206,33 +174,32 @@ https://docs.netlify.com/routing/redirects/redirect-options/#trailing-slash.
206174
Page and exact redirects without a wildcard at the end will be normalized,
207175
all other redirects need to be matched as is.
208176

209-
Improving exact redirects
210-
~~~~~~~~~~~~~~~~~~~~~~~~~
177+
This makes it impossible to match a path with a trailing slash.
211178

212-
- Explicitly place the ``$rest`` placeholder in the target URL,
213-
instead of adding it automatically.
179+
Explicit ``$rest`` placeholder
180+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
214181

215-
Some times users want to redirect to a different path,
216-
we have been adding a query parameter in the target URL to
217-
prevent the old path from being added in the final path.
218-
For example ``/new/path/?_=``.
182+
Explicitly place the ``$rest`` placeholder in the target URL,
183+
instead of adding it automatically.
219184

220-
Instead of adding the path automatically,
221-
users have to add the ``$rest`` placeholder in the target URL.
222-
For example:
185+
Some times users want to redirect to a different path,
186+
we have been adding a query parameter in the target URL to
187+
prevent the old path from being added in the final path.
188+
For example ``/new/path/?_=``.
223189

224-
- From: ``/old/path/$rest``
225-
To: ``/new/path/$rest``
190+
Instead of adding the path automatically,
191+
users have to add the ``$rest`` placeholder in the target URL.
192+
For example:
226193

227-
- From: ``/old/path/$rest``
228-
To: ``/new/path/?page=$rest&foo=bar``
194+
From:
195+
``/old/path/$rest``
196+
To:
197+
``/new/path/$rest``
229198

230-
- Per-domain redirects.
231-
Do users have the need for this?
232-
The main problem is that we were applying the redirect
233-
to external domains, if we stop doing that, is there the need for this?
234-
We can also try to improve how our built-in redirects work
235-
(specially our canonical domain redirect).
199+
From:
200+
``/old/path/$rest``
201+
To:
202+
``/new/path/?page=$rest&foo=bar``
236203

237204
Improving page redirects
238205
~~~~~~~~~~~~~~~~~~~~~~~~
@@ -307,6 +274,52 @@ Other ideas to improve redirects
307274
adding support for a prefix wildcard should be easy.
308275
But do users need this feature?
309276

277+
- Per-domain redirects.
278+
The main problem that originated this request was that we were applying redirects on external domains,
279+
if we stop doing that, there is no need for this feature.
280+
We can also try to improve how our built-in redirects work
281+
(specially our canonical domain redirect).
282+
283+
Allow matching query arguments
284+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
285+
286+
We can do this in two ways:
287+
288+
- At the DB level with some restrictions.
289+
If done at the DB level,
290+
we would need to have a different field
291+
with just the path, and other with the query arguments normalized and sorted.
292+
293+
For example, if we have a redirect with the value ``/foo?blue=1&yellow=2&red=3``,
294+
if would be normalized in the DB as ``/foo`` and ``blue=1&red=3&yellow=2``.
295+
This implies that the URL to be matched must have the exact same query arguments,
296+
it can't have more or less.
297+
298+
I believe the implementation described here is the same being used by Netlify,
299+
since they have that same restriction.
300+
301+
If the URL contains other parameters in addition to or instead of id, the request doesn't match that rule.
302+
303+
https://docs.netlify.com/routing/redirects/redirect-options/#query-parameters
304+
305+
- At the Python level.
306+
If done at the DB level,
307+
we would need to have a different field
308+
with just the path, and other with query arguments.
309+
310+
The matching of the path would be done at the DB level,
311+
and the matching of the query arguments would be done at the Python level.
312+
Here we can be more flexible, allowing any query arguments in the matched URL.
313+
314+
We had some performance problems in the past,
315+
but I believe it was mainly due to the use of regex instead of using string operations.
316+
And matching the path is still done at the DB level.
317+
We could limit the number of redirects that can be created with query arguments,
318+
or the number of redirects in general.
319+
320+
We hava had only one user requesting this feature,
321+
so this is not a priority.
322+
310323
Migration
311324
---------
312325

0 commit comments

Comments
 (0)