Using Next.js's rewrite feature I would like to be able to intercept the response and change e.g. headers and even links in the body.
I have a front-facing next.js web app which is accessible by the visitors. Some parts come from a different service, but the visitor should not see those details, for her the URL should look like all comes from a single source, and all navigation goes inside the same hostname.
I used the rewrites() of next.config.js according to Incremental adoption of Next.js and this works for the most part. But the responses from the other background service sometimes contain wrong URLs / hostnames. Those I would like to replace to match the public facing hostname of the web site.
I couldn't find any pointers on the next.js documentatin as to how best approach this problem. Maybe someone has a solution to share or there exist some middleware already?
Rewrites are simply a way to map a request path to a different destination path. Rewrites don't allow you to modify the contents of the page you're rewriting to.
You'll have to modify the destination app yourself to reflect the changes you want.
Related
I have a firebase site with a domain of gs-domain1.web.app.
I have a second firebase site with a domain of gs-domain1.web.app.
Now, I want all traffic to go through the gs-domain1.web.app. However, when the path matches a specific route, like, /users/:id/pages, I want the site on gs-domain2.web.app to take over without switching the domain, but maintaining the path.
I believe a redirect will not work because it physically switches the domain.
I believe a rewrite will not work because I can't recreate the path on the destination.
Both the application on domain1 and domain2 are single-page applications (react and vue respectfully).
In firebase, you could host more than one site in one project and that would solve your problem.
Host/Deploy the react code to firebase and link the site with the URL of gs-domain2.web.app
and
do another hosting in the same project as the react but vue on gs-domain2.web.app
After you have successfully linked the domain and hosted the sites... Link the URL together with or anyone you like.
PROS: Your sites would load separately and would be faster.
Also,
It would be great if you put all the code under one domain
Then you can use different paths for the 2 sites so they would be easily identifiable.
so you have : gs-domain1.web.app/path1 and gs-domain1.web.app/path2
You will find the add another site function at the bottom of the hosting section below 1
I am not sure exactly what you mean by "take over without switching the domain, but maintaining the path". If you mean that you want the user to now see the page on gs-domain1.web.app when at this specific path, but still have gs-domain1.web.app as the domain in the url in their browser, I can only really think of two good ways to do this.
You use an iFrame to display the page from gs-domain2.web.app as the entire contents of the page on gs-domain1.web.app at the specific path. This can potentially introduce weirdness if the second page is complex.
You get rid of the second domain and instead move that codebase over to the first domain and write some middleware that serves from the first codebase whenever the user is requesting a path that should come from gs-domain1.web.app currently and serves from the second codebase whenever a user requests a path that should currently be coming from gs-domain2.web.app. I feel that this would be the more 'correct' approach if this is the desired behavior you want.
Alternatively, if you do not care what domain the user is seeing, I would suggest, as you mentioned, merely setting up some clever redirects to bounce users between the two based on which path they are requesting.
I hope this was helpful and goodluck!
I have a page as part of my IIS 7 (ASP.NET) website which serves images from a database. It uses a querystring to select the image and sets the content type header appropriately (image/jpeg) so that, for example, image.aspx?ID=1234 will be displayed in the browser as a jpeg image.
What I want to do instead is offer a URI formed in a manner such as image/1234.jpg which will produce the same result. In other words, there is no actual file on the server named 1234.jpg, it's just the contents of a database record, but from the browser's perspective, it will appear as if there is such a file.
I'm sure this is possible, but I can't figure out how it's accomplished, or where to look for answers. I'm thinking it may be done with an ISAPI filter, but I haven't found an accessible path into the docs to know if that's even the correct basis for a solution.
Possibly the best option here would be to implement a URL rewrite rule that changes image/1234.jpg to image.aspx?ID=1234
You can find more on URL rewrite for IIS here.
If, for whatever reason, URL rewrite isn't an option to you, then another possible method might be to implement a custom 404 page. When your request to image/1234.jpg doesn't result in a real file, it'll end up there.
You should be able to detect the URI at that point and serve up the image.
I have a currently existing site with URL re-writing enabled using ISAPI Rewrite and IIRF files, the problem is it's causing a lot of problems, both for site development / maintenance and because of continuous errors on the server.
Because of this I'm looking to replace it with .Net 4.0's URL Routing.
I'm having two problems with this, first, the current routing rules are set up so that the page being routed to is simply the re-written URL with the file extension appended to the end.
So www.site.com/page/ would become www.site.com/page.aspx
The second problem is that certain re-written URL's actually point to physical files within sub-folders on the website using the same logic as above.
So www.site.com/folder/page/ would redirect to www.site.com/folder/page.aspx
I've read through this article and created custom IRouteHandler and IHttpHander implemented classes, but I'm not really sure where to go from here.
I've tried a few different things, mainly related to variables in the URL and trying to redirect to them, but I'm not sure that's the right way for me to go.
I'm not posting code because all I have at the moment is pretty much the example code from the link above.
I've implemented basic routing on another site where a single page uses a variable in the URL to grab the relevant content out of a database, and that seemed simple enough, but this is making my head spin, I'm sure it shouldn't be this complicated.
For the past few years, if I've wanted a URL of a page on a site rewritten I've put the rewritten URL into the link on the page.
E.g. If the page is /Product.aspx?filename=ProductA and it's rewritten to /Product/ProductA.aspx then I've put the following in my link:
...
However, with outbound rules I could just put the links in to the actual file paths, and rewrite with an outbound rule.
Is this a bad method? Would it cost the server unnessacery additional resources?
I would not consider this bad practice. Infact it affords you some additional flexibility as your mapping for friendly to real url's is all managed in one central location. If your seo team decide they want to change the url scheme, you dont have to pick through all the links on your site updating them- risking missing one!
One important limitation of the current version of the IIS rewrite module, is you cannot use outbound rewriting in conjunction with Static compression- However you can still use Dynamic compression. Static compression is nice because it will cache the compressed version of the page. See this article for instructions on getting url rewrite working with Dynamic compression: http://forums.iis.net/p/1165899/1950572.aspx
The situation is the following: I created a site with Plone, developed, used, but behind a test URL. Now it has to be published, but the test URL is not appropriate and I don't want to move the site. I think, if I use a redirect, it won't be appear in the URL-bar, only in the case of site start page. Am I wrong? (The test URL should not be used, because it will be a "semi-official" site.) What do you suggest to do?
As far as I can see Plone uses absolute URLs everywhere. I can add relative URLs, but if I create a new page, a new event, etc., then they have absolute URLs on other automatically generated inner pages. Is there any way to convert these URLs to relative paths? Is there any setting possibilty where only a checkbox changes this default setting?
Plone does not store your URLs in the database. It uses the inbound host header (and any virtual hosting configuration set up with rewrite rules in Apache or Nginx) to calculate the correct absolute URL when rendering the page.
In other words - as soon as you actually point the relevant domain name to the server with your Plone instance, it'll just work.
P.S.
You should put a bit more effort into asking your question. This is just a copy and paste of a half-finished email chain where you tried to get the answer from me in private. It's not very easy to understand what you're asking.
I think what you are looking for is url rewriting to handle virtual hosting. ie to get your site to appear as if it's the root url of a domain.
This is normally done via the webserver that normally sits in front of plone. For apache, here is a howto
http://plone.org/documentation/kb/plone-apache/virtualhost
for other servers
http://plone.org/documentation/manual/plone-community-developer-documentation/hosting
You can also achieve this directly in zope (via ZMI) using something called the Virtual Host
Monster. see http://docs.zope.org/zope2/zope2book/VirtualHosting.html
PS. I don't think your question is badly worded. Plone does serve pages with a "base" tag and what appears to be absolute urls. They aren't baked into the database but it's also not obvious that the solution to getting the url you want is the VHM url syntax and a proxying frontend webserver. There is a reason why it doesn't use relative urls... which I can't remember it was so long ago.