Redirects
Authors: @szainmehdi
Type: Feature
Overview
Provide a way for the frontend to implement 301 Permanent Redirects when slugs change for reciters, albums, and tracks. Additionally, attempt to import old URLs from the original nawhas.com and preserve those with redirects as much as possible.
Why are we making this change?
When a reciter’s name changes, the slug is updated, and all previous links (nested under /reciters/{slug}
) are invalidated and begin to 404. This is terrible for user experience, and terrible for SEO. Similar situations arise when changing the year
of an album, or the title of a track.
To preserve old links, we need to implement a 404 handler on the frontend, and a way for the frontend to determine what the new link should be.
Requirements
Detailed Engineering Design
API
When certain events are fired, like ReciterNameChanged
, TrackTitleChanged
, or AlbumYearChanged
, we need to write records to the database to support redirects.
Database Changes
reciter_aliases
field | type | notes |
---|---|---|
id | uuid | PK |
reciter_id | uuid | FK for reciters.id |
alias | string | An old slug |
album_aliases
field | type | notes |
---|---|---|
id | uuid | PK |
reciter_id | uuid | FK for reciters.id |
album_id | uuid | FK for albums.id |
alias | string | An old slug |
track_aliases
field | type | notes |
---|---|---|
id | uuid | PK |
reciter_id | uuid | FK for reciters.id |
album_id | uuid | FK for albums.id |
track_id | uuid | FK for tracks.id |
alias | string | An old slug |
Endpoint
POST /v1/redirect
{
"parameters": {
[key: string]: string;
}
}
(example)
POST /v1/redirect
{
"parameters": {
"reciter": "the-tejani-brothers",
"album": "2018"
}
}
Responses:
- 404: no redirect found
- 200: redirect found
200 OK
{
"to": "/reciters/tejani-brothers/albums/2018-19",
}