mirror of
https://github.com/jbranchaud/til
synced 2026-01-03 23:28:02 +00:00
Add Add Web Server Layer Redirects as a Vercel til
This commit is contained in:
@@ -9,7 +9,7 @@ and pairing with smart people at Hashrocket.
|
||||
|
||||
For a steady stream of TILs, [sign up for my newsletter](https://tinyletter.com/jbranchaud).
|
||||
|
||||
_957 TILs and counting..._
|
||||
_958 TILs and counting..._
|
||||
|
||||
---
|
||||
|
||||
@@ -44,6 +44,7 @@ _957 TILs and counting..._
|
||||
* [Shell](#shell)
|
||||
* [tmux](#tmux)
|
||||
* [Unix](#unix)
|
||||
* [Vercel](#vercel)
|
||||
* [Vim](#vim)
|
||||
* [VSCode](#vscode)
|
||||
* [Webpack](#webpack)
|
||||
@@ -934,6 +935,10 @@ _957 TILs and counting..._
|
||||
- [Watch This Run Repeatedly](unix/watch-this-run-repeatedly.md)
|
||||
- [Where Are The Binaries?](unix/where-are-the-binaries.md)
|
||||
|
||||
### Vercel
|
||||
|
||||
- [Add Web Server Layer Redirects](vercel/add-web-server-layer-redirects.md)
|
||||
|
||||
### Vim
|
||||
|
||||
- [Aborting Git Commits And Rebases](vim/aborting-git-commits-and-rebases.md)
|
||||
|
||||
36
vercel/add-web-server-layer-redirects.md
Normal file
36
vercel/add-web-server-layer-redirects.md
Normal file
@@ -0,0 +1,36 @@
|
||||
# Add Web Server Layer Redirects
|
||||
|
||||
People create links and bookmark URLs. Content, for a variety of reasons, has
|
||||
to move from one place to another. For everyone's sake, you don't want to break
|
||||
the URLs that people have come to rely on.
|
||||
|
||||
You need to setup some
|
||||
[redirects](https://vercel.com/docs/configuration#project/redirects).
|
||||
|
||||
Though a [Next.js](https://nextjs.org/) app is just frontend code, when
|
||||
distributed through [Vercel](https://vercel.com/), you can include some
|
||||
configuration of the web server layer.
|
||||
|
||||
Add the `vercel.json` file to the top-level directory of your Next.js project
|
||||
and then include any needed redirect rules.
|
||||
|
||||
```json
|
||||
{
|
||||
"redirects": [
|
||||
{
|
||||
"source": "blog/old-blog-post-name",
|
||||
"destination": "blog/new-blog-post-name"
|
||||
},
|
||||
{
|
||||
"source": "/store",
|
||||
"destination": "store.example.com"
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
In the first rule, one path is redirected to another for the same domain. In
|
||||
the second rule, the path is redirected to an external URL.
|
||||
|
||||
By default, these redirects get a [308 status
|
||||
code](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/308#:~:text=The%20HyperText%20Transfer%20Protocol%20(HTTP,given%20by%20the%20Location%20headers.).
|
||||
Reference in New Issue
Block a user