IIS Redirects preserve path - redirect

I'm trying to achieve the following via IIS:
Redirect requests for App-A to Server-A
Redirect requests for App-B to Server-B
Redirect everything else to Server-C
I have 1 & 2 working via simple redirect rules:
1.
Requested URL: Matches the pattern
Pattern: ^App-A
Action type: Redirect
Redirect URL: https://Server-A.fqdn/App-A
2.
Requested URL: Matches the pattern
Pattern: ^App-B
Action type: Redirect
Redirect URL: https://Server-B.fqdn/App-B
3.
I haven't sorted this one out yet.
The following is not working:
Requested URL: Does not match the pattern
Pattern: ^App-A, ^App-B
Action type: Redirect
Redirect URL: https://Server-C.fqdn/
Seems that the requested path is not preserved and appended to the redirect URL therefore the destination is unreachable.

3.
Requested URL: Matches the pattern
Pattern: ^(.*)
Action type: Redirect
Redirect URL: https://Server-C.fqdn/{R:0}
Since rules are processed in order, rule 3 is successfully processed for everything else ^(.*) when the request does not match rule 1 (/App-A) or rule 2 (/App-B). {R:0} preserves the path.

Related

Nextjs change 308 to 301 redirect

My task is to set up a redirect from pages with a trailing slash to a page without a trailing slash through 301 redirects for SEO.
By default, nextjs has a 308 redirect configured.
Now:
/catalog/123/ -> /catalog/123 308 redirect
What I expect:
/catalog/123/ -> /catalog/123 301 redirect
/catalog/99/ -> /catalog/99 301 redirect
I'm trying to do it this way. What is my mistake?
module.exports = {
async redirects() {
return [
{
source: '/catalog/:slug/',
destination: '/catalog/:slug',
statusCode: 301,
},
]
},
}
I have seen that it is possible to configure redirect in getServerSideProps, but in my case it is getStaticProps.
upd:
Code project example https://stackblitz.com/edit/nextjs-g2zvta?file=pages/posts/[id].js
Link example. posts/1/ redirect to posts/1 with 308
https://nextjs-g2zvta--3000.local.webcontainer.io/posts/1/
GetStaticProps() only runs at build time. You have to organize middlewares for redirects on static pages. Unlike the config you have (almost) full control over the response stats in there.

Moving HTTP site to HTTPS on Netlify - 301 Redirects and SEO

I am moving my old HTTP site to Netlify and need some guidance on 301 redirects and SEO.
I will be using netlify.toml for redirects.
Netlify will automatically redirect http://www.example.com to https://www.example.com so I'm assuming that a redirect rule is not needed for this case.
Question 1: For http://example.com to https://www.example.com - should I do this in DNS or 301 redirect rule in netlify.toml?
For the following URL
http://www.example.com/directory/page1.html
Question 2: Should I use relative or absolute URLs to redirect? Which from below would be a best-case scenario?
[[redirects]]
from = "/directory/page1.html"
to = "https://www.example.com/directory/:splat"
status = 301
force = true
[[redirects]]
from = "http://www.example.com/directory/page1.html"
to = "https://www.example.com/directory/:splat"
status = 301
force = true

How does one setup OpenAPI redirect response with parameters?

I have an HTTP 302 (Redirect) that I implemented a new status parameter, that will append to the RedirectURL, so one can show a message something like
if the call URL is passed as
GET http://localhost:8080/info/status?redirectUrl=http://localhost:8080/redirect
then it will redirect as
http://localhost:8080/redirect?status=success
and it's counterpart
http://localhost:8080/redirect?status=error
but how does one describe this in OpenAPI specification? I can't seem to make use of parameters in the response and found some code that uses responseParameters but I had no luck to make it work... don't even know if it's something that is supported, at least, I get no errors compiling with both commands
/info/setup:
get:
summary: Setup Url
description: Setup Url to create new setup. Should be retrieved from api
apps endpoint and redirect to, not called directly by the url defined
here
parameters:
- in: query
name: installationId
description: The installation id
required: true
schema:
type: string
- in: query
name: redirectUrl
description: Url to redirect back to upon finished installation
required: true
schema:
type: string
responses:
"302":
description: Redirect
responseParameters:
- in: query
name: status
description: the status of the instalation
schema:
oneOf:
- type: string
example: success
description: When the installation was successful
- type: string
example: error
description: When the installation was erroneous
headers:
location:
description: Setup state based redirect
schema:
oneOf:
- type: string
description: If setup is done and valid for installation id, will
redirect to given redirect url
- type: string
description: If no setup exist for installation id, will redirect to
SumUp oauth page
- type: string
description: If error during authorization with SumUpl, e.g. non
matching editions, will redirect to a setup page for
further user action
what is the common way of having such a scenario?
should we have 2 redirect URLs like
GET http://localhost:8080/info/status
?redirectUrl=http://localhost:8080/redirect
&errorUrl=http://localhost:8080/redirect_error
I'm a bit of a loss on this simple predicament, maybe someone can help 😊
Yes, this is an annoying issue with OpenAPI. You cannot really specify a redirect explicitly.
The best you can do is specify a response with a status code in the 3xx redirect range (301, 302, 303, 307, 308) that has a "location" header parameter of type "string".
You should then add a description and summary - pretty much what you have already done.
There is this issue in the OpenAPI specification github: https://github.com/OAI/OpenAPI-Specification/issues/2512
Hopefully something will be done soonish.

IIS7 HTTP Redirect - how to drop/ignore the original's relative path?

Using IIS7's built in "HTTP Redirect" for a site.
Problem
Entering: original.com/abc/efg
Gives: redirect.com/abc/efg - which is not a page on the redirect destination!
I want
Entering: original.com/abc/efg
Gives: redirect.com
I already Checked "Redirect all requests to exact destination"
Note - while original.com/abc/efg does NOT give redirect.com...
original.com/abc/efg/ (include ending slash) DOES give redirect.com. Bug with IIS7 HTTP Redirect?

Nginx redirect http to https and remove trailing slashes with one single redirect

I want to redirect http to https and remove trailing slashes in nginx with one single redirect. The solution I have today is the following:
server {
listen 80;
server_name www.example.com
rewrite ^/(.*)/$ /$1 permanent;
return 301 https://$host$request_uri;
}
The problem with this solution is that it will give two redirects
Gives Two redirects:
http://www.example.com/test/ --> http://www.example.com/test
http://www.example.com/test --> https://www.example.com/test
Is it possible to make a solution where you only get one single redirect like bellow?
http://www.example.com/test/ --> https://www.example.com/test
when I looked through the documentation of nginx rewrite and return methods I felt like it should be possible to do it with a single rewrite somehow:
rewrite ^/(.*)/$ https://$host$request_uri permanent;
But nothing I have tried have given me the correct results.
You already had the components of a correct solution. Use the scheme and hostname, together with the capture to construct the destination URL:
rewrite ^/(.*)/$ https://$host/$1 permanent;