This repository has been archived by the owner on Jun 21, 2023. It is now read-only.
forked from vercel/next.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add handling for repeated slashes (vercel#27738)
This adds handling for repeated forward/back slashes in Next.js, when these slashes are detected in a request to Next.js we will automatically remove the additional slashes redirecting with a 308 status code which prevents duplicate content when being crawled by search engines. Fixes: vercel#13011 Fixes: vercel#23772 Closes: vercel#15171 Closes: vercel#25745
- Loading branch information
Showing
13 changed files
with
688 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
module.exports = { | ||
redirects() { | ||
return [ | ||
{ | ||
source: '/redirect-forward-slashes', | ||
destination: '/test//google.com', | ||
permanent: false, | ||
}, | ||
{ | ||
source: '/redirect-back-slashes', | ||
destination: '/test\\/google.com', | ||
permanent: false, | ||
}, | ||
] | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
if (typeof window !== 'undefined') { | ||
window.errorLoad = true | ||
} | ||
|
||
export default function Page() { | ||
return <p id="error">custom error</p> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default function Another() { | ||
return <p id="another">another page</p> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default function Index(props) { | ||
return <p id="index">index page</p> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import Link from 'next/link' | ||
|
||
if (typeof window !== 'undefined') { | ||
window.caughtErrors = [] | ||
const origError = window.console.error | ||
|
||
window.console.error = function (...args) { | ||
window.caughtErrors.push(args.join(' ')) | ||
return origError(...args) | ||
} | ||
} | ||
|
||
export default function Invalid() { | ||
return ( | ||
<> | ||
<p id="invalid">invalid page</p> | ||
<Link href="/another" as="//google.com"> | ||
<a id="page-with-as-slashes">to /another as //google.com</a> | ||
</Link> | ||
<br /> | ||
|
||
<Link href="//google.com"> | ||
<a id="href-with-slashes">to //google.com</a> | ||
</Link> | ||
<br /> | ||
|
||
<Link href="//google.com?hello=1"> | ||
<a id="href-with-slashes-query">to //google.com?hello=1</a> | ||
</Link> | ||
<br /> | ||
|
||
<Link href="//google.com#hello"> | ||
<a id="href-with-slashes-hash">to //google.com#hello</a> | ||
</Link> | ||
<br /> | ||
|
||
<Link href="/another" as="\/\/google.com"> | ||
<a id="page-with-as-backslashes">to /another as \\/\\/google.com</a> | ||
</Link> | ||
<br /> | ||
|
||
<Link href="\/\/google.com"> | ||
<a id="href-with-backslashes">to \\/\\/google.com</a> | ||
</Link> | ||
<br /> | ||
|
||
<Link href="\/\/google.com?hello=1"> | ||
<a id="href-with-backslashes-query">to \\/\\/google.com?hello=1</a> | ||
</Link> | ||
<br /> | ||
|
||
<Link href="\/\/google.com#hello"> | ||
<a id="href-with-backslashes-hash">to \\/\\/google.com#hello</a> | ||
</Link> | ||
<br /> | ||
</> | ||
) | ||
} |
Oops, something went wrong.