Next.js Discord

Discord Forum

Page alias to aggregate and hide query parameters for google indexing

Answered
Masai Lion posted this in #help-forum
Open in Discord
Masai LionOP
I have a project where I have games and publishers.
This project has a single indexing page for games where you can pre-set filters. i.e. /games?publisher=relogic
I want to create one page for each publisher, but I want to use this indexing page template. What's the best approach to do this?
i.e. /publishers/relogic would map to -> /games?publisher=relogic
Answered by Western paper wasp
You could use a middleware to rewrite paths of the form /publishers/relogic to /games?publisher=relogic

Then, you could add markup to the /games page to include a <link rel="canonical" href="your-site.com/publsihers/reglogic"> in the <head>, which would ensure search engines index that version rather than the query param version
View full answer

8 Replies

Western paper wasp
You could use a middleware to rewrite paths of the form /publishers/relogic to /games?publisher=relogic

Then, you could add markup to the /games page to include a <link rel="canonical" href="your-site.com/publsihers/reglogic"> in the <head>, which would ensure search engines index that version rather than the query param version
Answer
but you'll need to make sure the page is also accessible by your preferred URL, or the canonical URL won’t work; a rewrite in middleware.js should be able to take care of that
Western paper wasp
You’re welcome!
Feel free to mark as solution
Masai LionOP
Yeah I forgot this server has this functionality.