AWS Application Load Balancer redirect all www and non http to https:// - amazon-web-services

I have a rule setup to redirect all traffic from http to https
How can I also redirect http://www to https://? As far as I can tell the {host} variable contains www and I cant remove it.

In fact it's pretty simple
Instead of writing {host} in your rule just put the name of your website.
So, for example, it will look like this :
https://example.com:443/#{path}?#{query}

Related

Regex - redirect from website.com to website.com/us and append substring

Can anyone help me correct my regex?
My hosting provides IP geolocation and I want to redirect US clients to another sub-directory of my website.
The website runs on a Nginx server and the hosting provides an interface where one can add redirection rules. The interface consists of Domain, Redirect from, Redirect To, Traffic from (country) and HTTP status code 301 or 302.
Example:
for all non-US clients website.com/blog/article/really-good-book
only for US clients website.com/us/blog/article/really-good-book
I currently have:
Redirect from ^/(?!us/)(.*)$
Redirect to /us/$1
This currently redirects me to website.com/us/index.php and nothing else. So the redirect is applied, it only appends index.php instead of blog/article/really-good-book.
Thank you for your help.
Eventually I found my own solution:
Redirect from ^(?!(/us|/index.php|/wp-admin|/wp-login.php))(.*)$
Redirect to /us/$1
I also added a rule for my wordpress backend, otherwise it would always redirect me back to website.com/us while trying to access website.com/us/wp-admin.

AWS redirect in Load Balancer to work with POST and PUT

I want to do something similar to this: Create AWS Application Load Balancer Rule which trim off request's prefix without using additional reverse proxy like nginx, httpd
Using AWS Load balancer, to redirect traffic from URL say /foo to /bar like this:
But only GET requests are routed correctly and POST,PUT,etc get routed as GET so I'm getting an error because my controller doesn't have those GET methods.
Is there a way to do this with AWS load balancer?
The question I linked is from 2016 so I was hoping something has changed in 5 years.
In case someone is using a client written in Golang, this is why redirected POST requests end up as GET on the server side:
https://github.com/golang/go/issues/18570
https://cs.opensource.google/go/go/+/master:src/net/http/client.go;l=514
In the section in which you define the condition you have to specify the http method, otherwise it will consider GET as default.
Example for the OPTIONS HTTP calls
You can use /* in the IF section with a path as a condition.
For example, IF /* THEN Redirect to.
Additionally, you can use one of more condition in the IF section such as host-header, http-request-method, query-string, source-ip
there's http request methode option
check this screenshot
you can put there PUT or POST or GET like:
this

How to rewrite subdirectory name in iis

My website is located at:
example.com/NAME/home.aspx?id=1
I want to make it so this url works without redirecting to original:
example.com/DIFFERENTNAME/home.aspx?id=1
Also, when hitting the first url, I want it to be redirected to the 2nd.
I have url rewrite module Tried modifying several inbound rules, but cannot make it to work.
You can use HTTP Redirect and reference link follows
https://www.iis.net/configreference/system.webserver/httpredirect

Can I set up a CNAME catch-all redirect from one subdomain level to a higher subdomain?

I have hundreds of subdomains set up for environments in Route53 for AWS that look like this:
<appX>.dev.internalurl.us
<appX>.qa.internalurl.us
<appX>.pt.internalurl.us
<appX>.internalurl.us
The issue is that our production internal urls are missing the 'prod' env in the url which requires us to add conditionals to all our config scripts, like:
if 'prod.' in url:
url = url.substring('prod.', '')
What I'd like is:
<appX>.prod.internalurl.us to go to <appX>.internalurl.us automatically.
EDIT:
I added a CNAME to route prod.internalurl.us to internalurl.us like so:
*.prod.internalurl.us > internalurl.us
but this obviously won't work since I need a capture group on the wildcard! It's ignoring the first "appX" subdomain.
I don't want to have to enter in hundreds of CNAMES,so am looking for a catch-all redirect for one sub-domain level to its parent.
Is there a way to do this with CNAME or does it require running an nginx proxy at prod.internalurl.us to make this work?
The solution that may help is simple enough. To find it out let me ask a question. Why do you need this functionality on DNS level?
What I'd like is:
.prod.internalurl.us to go to .internalurl.us
automatically.
CNAME doesn't help with conditional URL rewrite, there is no such logic on that layer. What helps is HTTP layer 301 redirect can be managed via Nginx:
server {
server_name ~^(?<app>.+)\.prod\.internalurl\.us$;
return 301 http://$app.internalurl.us$request_uri;
}
There is no proxy but HTTP 301 redirect instead.

Mapping a naked URL to the equivalent www URL

I'm currently using dotcloud hosting for an application and I'm redirecting my naked url using my domain registrar namecheap (through "#" hostname and "*" hostname as a URL direct- and then a cname for www to dotcloud)
This works well for re-directing people back to main www.
My issue is I want to map the visitor to the equivalent naked domain url they were trying to visit. E.g. http://example.com/websitepage1 to http://www.example.com/websitepage1. Right now visiting any page on the site minus the "www" will just redirect you to the homepage.
Any ideas or suggestions?? I'd prefer not to switch out of dotcloud hosting for the moment but will do so if it's impossible to get this to work another way.
Thanks!
UPDATE
The urls that need to be redirected are created dynamically so it's not impossible to hard code them. The DNS doesn't have to be namecheap. I can put the nameservers else where if there is an option that allows redirect of naked urls to the www equivalent. Any ideas appreciated!
You need to add rewrite rules to nginx.conf:
server {
server_name hostname.org;
rewrite ^(.*) http://www.hostname.org$1 permanent;
}
You can specify custom rewrite rules (and actually almost any Nginx setting) by creating a file named nginx.conf at the top of your app. http://docs.dotcloud.com/0.9/guides/nginx/
Given their documentation (0), it seems possible to do the following 301/302 redirects using Namecheap's forwarding options:
Setup a naked domain redirect from example.com to www.example.com
Setup a naked domain redirect with a url from example.com/url/ towww.example.com/url/`
I don't see in the documentation where it says they support a wildcard option, so for every url you'd like to support, it seems you may have to create a forwarding entry.
(0): http://www.namecheap.com/support/knowledgebase/article.aspx/385/77/how-do-i-setup-url-forwarding-for-a-domain