-
Notifications
You must be signed in to change notification settings - Fork 233
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changing posts path #155
Comments
For future fellows that comes accross this post, here is what I have done to solve this issue. To change the path of the posts from
|
<Link | |
as={`/posts/${post.filePath.replace(/\.mdx?$/, '')}`} | |
href={`/posts/[slug]`} | |
> |
After:
<Link
as={post.filePath.replace(/\.mdx?$/, '')}
href={`/${post.filePath.replace(/\.mdx?$/, '')}`}
>
slug.js
In the slug.js
file, you need to update the Link
components' href
prop as follows:
Before:
After:
{prevPost && (
<Link href={`/${prevPost.slug}`}>
{nextPost && (
<Link href={`/${nextPost.slug}`}>
next.config.js
Create a next.config.js
file in the root directory of your Next.js project if it doesn't exist already. Add the following code to the file:
module.exports = {
async rewrites() {
return [
{
source: '/:slug*',
destination: '/posts/:slug*',
},
];
},
};
After making these changes, the post URLs will be updated to the desired structure. For example, https://website-name.com/posts/test-post
will become https://website-name.com/test-post
.
Please note that you may need to restart your Next.js development server for the changes to take effect.
The current post path is
https://website-name.com/posts/
. Is there a way I could change it tohttps://website-name.com/
?For example, from
https://website-name.com/posts/test-post
tohttps://website-name.com/test-post
.As my previous blog uses this post structure, I would like to retain the post structure for consistent SEO result.
The text was updated successfully, but these errors were encountered: