Skip to content
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

Rewrite path #14788

Closed
TibiTotoro opened this issue Jun 14, 2019 · 8 comments
Closed

Rewrite path #14788

TibiTotoro opened this issue Jun 14, 2019 · 8 comments
Labels
stale? Issue that may be closed soon due to the original author not responding any more.

Comments

@TibiTotoro
Copy link

For some pages, i want to to change the URL path in the router to not map directly to the path on the filesystem.
These pages will be placed on subdomains, all such pages are building to a folder /test/, we get /test/subdomain1/index.html, /test/subdomain2/index.html, /test/subdomain3/index.html etc.

Redirection is configured by Nginx, but gatsby take path from gatsby-script-loader and a page subdomain.domain.com redirected to subdomain.domain.com/test/subdomain1/index.html

I saw that a similar question about path rewriting was raised in #3113 and #383 but there is no solution to these questions.

Is there any solution to this problem? Thanks!

@sidharthachatterjee
Copy link
Contributor

You should be able to do this using path prefixes.

Read more about this at https://www.gatsbyjs.org/docs/path-prefix/

@TibiTotoro
Copy link
Author

Wow, how quickly closed the question)
I found a solution to this problem in 4337, the plugin https://github.com/wardpeet/gatsby-plugin-static-site helps to remove unnecessary redirects.
Вut I'm not sure this is the best solution.
@sidharthachatterjee, сould you describe in more detail how path-prefix can help me? I need to build pages for the main domain in one project, as well as pages for all subdomains in the same project, in the folders demo/subdimain1, demo/subdimain2, demo/subdimain3. There are many subdomains and they are of the same type. All redirect will will be made Nginx.
This task is more like building several app in one project, but in several similar questions I did not find simple solution to this problem.

@sidharthachatterjee
Copy link
Contributor

@TibiTotoro Sorry for closing this too soon!

Let me elaborate. Path prefixes let you host at something other than at the the root (/) of the domain.

For example in your case, you could build the sites for each sub domain independently and put in folders demo/subdimain1, demo/subdimain2, demo/subdimain3. For this, you would set the path prefix as /subdimain1, /subdimain2 and /subdimain3 respectively.

@TibiTotoro
Copy link
Author

I understand correctly that you propose to run build several times, each time with your own path-prefix and put the files into different folders? Is there any way to automate this (there are many subdomains)? Is there any way to avoid duplication of static content such as images and documents that are the same for subdomains? If I duplicate static content 30-40 times, the output project will be terribly large.
In this moment i build project once, create pages for subdomains by createPages in gatsby-node.js, disable gatsby routing and set up redirects by nginx, вut i think, this may lead to problems.

@xavivars
Copy link
Contributor

@sidharthachatterjee: path-prefix allows to host at something other than /, but it doesn't allow you to host at something other than / while, at the same time, serving at a different URL where it's in the filesystem, because first thing gatsby app does is a "canonical check":

https://github.com/gatsbyjs/gatsby/blob/master/packages/gatsby/cache-dir/production-app.js#L69

in #4337 there was a proposal to introduce a config variable to disable such redirect, but was closed in favor of a workaround that doesn't work anymore.

@gatsbot
Copy link

gatsbot bot commented Jul 12, 2019

Hiya!

This issue has gone quiet. Spooky quiet. 👻

We get a lot of issues, so we currently close issues after 30 days of inactivity. It’s been at least 20 days since the last update here.

If we missed this issue or if you want to keep it open, please reply here. You can also add the label "not stale" to keep this issue open!

As a friendly reminder: the best way to see this issue, or any other, fixed is to open a Pull Request. Check out gatsby.dev/contributefor more information about opening PRs, triaging issues, and contributing!

Thanks for being a part of the Gatsby community! 💪💜

@gatsbot gatsbot bot added the stale? Issue that may be closed soon due to the original author not responding any more. label Jul 12, 2019
@gatsbot
Copy link

gatsbot bot commented Jul 23, 2019

Hey again!

It’s been 30 days since anything happened on this issue, so our friendly neighborhood robot (that’s me!) is going to close it.

Please keep in mind that I’m only a robot, so if I’ve closed this issue in error, I’m HUMAN_EMOTION_SORRY. Please feel free to reopen this issue or create a new one if you need anything else.

As a friendly reminder: the best way to see this issue, or any other, fixed is to open a Pull Request. Check out gatsby.dev/contribute for more information about opening PRs, triaging issues, and contributing!

Thanks again for being part of the Gatsby community!

@gatsbot gatsbot bot closed this as completed Jul 23, 2019
@digitaldiy
Copy link

Wouldn't this approach work?
https://nextjs.org/docs/api-reference/next.config.js/rewrites

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stale? Issue that may be closed soon due to the original author not responding any more.
Projects
None yet
Development

No branches or pull requests

4 participants