In many web applications and often on react applications is common to have an URL pattern served by the same content.
With apache, the .htaccess file can be setup to signal that an url PATTERN will be served by a single content file or script.
how can this achieved with the IPFS content gateway? is there a .htaccess equivalent?
How can I get the http gateway to serve multiple URLs with the same content?
Hey there @rvalle ,
I presume that your use-case is a single-page application where you want to be able to have all URLs handled by the same client side code which has its router.
Currently, this is not something that is supported by IPFS gateways.
There’s an ongoing spec discussion about enabling this kind of thing: IPIP: Gateway _redirects File by justincjohnson · Pull Request #290 · ipfs/specs · GitHub.
If you’re running your own gateway, you can put nginx or apache in front of it as a reverse proxy and handle this kind of this.
Alternatively, you can explore using hash-based routing. See the following blog post for more context Using Hashed vs. Non-Hashed URL Paths in Single Page Apps | by Viduni Wickramarachchi | Bits and Pieces
Yes, my use case is react or gatsby, where single or single/split app is used.
Yes, I am aware of the potential workarounds, but it would be good to have a first class HTTP content gateway.
I don’t think the pull request would address the same thing. HTTP redirects would not work in this context, would they?
In HTACCESS they talk about REWRITE, the URL as provided is right, but which file is going to handle is changed. This allows multiple URLs (Pattern) to be handled by the same File which will have to take the actual path as parameter in order to know how to render.
If you think about it, given that we serve the WebAPP ROOT by DNSLINK to a CID, there is already an “access” implementation in place that will take the path and match relative file path to find the content. That mechanism should be more powerful and allow multiple setttings.
There are other multiple problems that fall into this category, such as returning special headers, content types, redirects, etc.
I think IPFS http gateway needs an .htaccess equivalent solution. It is also important that this kind of rules can be distributed with the content, and not as infrastructure configuration.
It would. A redirects file would allow you to also do rewriting. It would work the same way as Netlify recommends doing it for single-page applications:
You would have the following line in the
/* /index.html 200
Yes, true. I missed this:
200 Redirect will be treated as a rewrite, returning OK without changing the URL in the browser.
then this would be a neat solution.
and what about custom content-type or other headers, is there a solution already of being worked out? I guess it should be coherent with the
Another great issue to track is Manifest files for unixfs loaded via HTTP Gateway · Issue #257 · ipfs/specs · GitHub for both redirects and custom headers and content types.
Hey @rvalle welcome. I’m on @justincjohnson’s team and we’re working on this specifically to support use cases of apps like yours.
I don’t think we’ve got a test environment up yet but when we do — we’d love for you to try it. I can come back to this thread with updates.
thanks @boris, @justincjohnson, I have also subscribed to notifications from the github PR.
As soon as you have a docker release I can test it. I have some applications in production that would benefit from this feature, like https://polkawatch.app where both UI and Data Packs are served over IPFS.