File tree Expand file tree Collapse file tree 2 files changed +43
-1
lines changed Expand file tree Collapse file tree 2 files changed +43
-1
lines changed Original file line number Diff line number Diff line change @@ -9,7 +9,7 @@ and pairing with smart people at Hashrocket.
9
9
10
10
For a steady stream of TILs, [ sign up for my newsletter] ( https://tinyletter.com/jbranchaud ) .
11
11
12
- _ 959 TILs and counting..._
12
+ _ 960 TILs and counting..._
13
13
14
14
---
15
15
@@ -32,6 +32,7 @@ _959 TILs and counting..._
32
32
* [ Mac] ( #mac )
33
33
* [ MongoDB] ( #mongodb )
34
34
* [ MySQL] ( #mysql )
35
+ * [ Next.js] ( #next-js )
35
36
* [ Phoenix] ( #phoenix )
36
37
* [ PostgreSQL] ( #postgresql )
37
38
* [ Python] ( #python )
@@ -423,6 +424,10 @@ _959 TILs and counting..._
423
424
- [ Show Tables That Match A Pattern] ( mysql/show-tables-that-match-a-pattern.md )
424
425
- [ Show Indexes For A Table] ( mysql/show-indexes-for-a-table.md )
425
426
427
+ ### Next.js
428
+
429
+ - [ Define URL Redirects In The Next Config] ( nextjs/define-url-redirects-in-the-next-config.md )
430
+
426
431
### Phoenix
427
432
428
433
- [ Bypass Template Rendering] ( phoenix/bypass-template-rendering.md )
Original file line number Diff line number Diff line change
1
+ # Define URL Redirects In The Next Config
2
+
3
+ In [ Add Web Server Layer Redirects] ( vercel/add-web-server-layer-redirects.md ) ,
4
+ I explained how to define URL redirects to your [ Vercel] ( https://vercel.com/ )
5
+ configuration for a [ Next.js] ( https://nextjs.org/ ) app. Because these redirect
6
+ rules are defined in ` vercel.json ` which is processed at the time of deployment
7
+ on the Vercel platform, you are unable to experience these redirects with your
8
+ local dev instance of the app. That could be misleading and cause confusion
9
+ during development.
10
+
11
+ Instead, you can define your redirects in ` next.config.js ` as part of the
12
+ Next.js app's configuration. When locally running the Next dev server, these
13
+ redirects will be processed and active.
14
+
15
+ Here is an example of these redirects in ` next.config.js ` :
16
+
17
+ ``` javascript
18
+ const nextConfig = {
19
+ async redirects () {
20
+ return [
21
+ {
22
+ source: " blog/old-blog-post-name" ,
23
+ destination: " blog/new-blog-post-name" ,
24
+ permanent: true ,
25
+ },
26
+ {
27
+ source: " /store" ,
28
+ destination: " store.example.com"
29
+ permanent: true ,
30
+ },
31
+ ]
32
+ },
33
+ }
34
+ ```
35
+
36
+ These will be 308 Permanent Redirects because of ` permanent: true ` . You can
37
+ change that to ` false ` to make them into 307s.
You can’t perform that action at this time.
0 commit comments