HAProxy 1.5 URL/URI Redirects to a different domain - redirect

I'm looking for a method to redirect visitors from https://site1.co.uk to https://site2.co.uk in HAProxy. I also need to redirect sub-pages (i.e. https://site1.co.uk/page1) to similar pages on site2.co.uk but using specific URLs. I have stuck a sample below of what I'd like to achieve if that helps...
Home redirect:
https://site1.co.uk -> https://site2.co.uk
Sub redirect:
https://site1.co.uk/first-page.html -> https://site2.co.uk/about-us.html
I've been searching for the last day or so for a simple solution to this problem and have been unable to find anything that does the trick.
I'm using HAProxy 1.5 (version required for a specific project) and any help would be much appreciated!
UPDATE
Things I've tried...had to remove HTTPS www.'s due to account limit.
redirect prefix site2.org.uk/subpage2/endresult2.html if { hdr(host) -i site1.org.uk }
redirect prefix site2.org.uk/subpage2/endresult2.html if { hdr(host) -i site1.org.uk/site1page.html }
Line 1: redirects correctly.
Line 2: End result is site2.org.uk/subpage2/endresult2/site1page.html - this is incorrect and should not include the site1page.html page on the end.
End result should be site2.org.uk/subpage2/endresult2 - this is how it I would like it to appear.
The server that HAProxy is on also serves multiple sites with different URLs. The above code is also redirecting them yet it shouldn't interact. How can I prevent this from happening?
UPDATE 2
I've noticed that when I enable a redirect, it's affecting my other sites which route through HAProxy and not just the one I'm trying to redirect (i.e. site1)

if you need to redirect your URL, you can check below link:
How to redirect URL with HAProxy
in haproxy you should use configuration like above

Although not technically the answer I wanted...I realised that I could redirect using the httpd configuration file instead of HAProxy. In the end that was the easiest option for a newbie like myself. Time will tell if this performs well...

Related

How to use URL Rewrite before HTTP Redirect on IIS

So I have a website running on IIS on an address like this: myserver.com/mysite.
From here I made a rule to redirect the site to: myserver.com/mysite/path/to/file.
I did this using the HTTP redirection module to make a 302 redirect to path/to/file and that works fine.
The problem is that if I dont put the trailing slash / at the end of mysite I get a 404 error, so I used the built-in template AddTrailingSlashRule in the URL Rewrite module.
So if I disable the redirect, the trailing slash gets added at the end of the website just fine, but once I enable the HTTP redirect, it sends me to myserver.com/path/to/file/ and obviously that doesn't work, because I get the redirect first and then the rewrite.
Is there a way to change the "order" of the modules? Or is there a better way to achieve this?
Thanks for any help!
For anyone having this problem in the future, I ended up disabling the HTTP redirect and made a new rule using the URL Rewrite module.
It simply matches the ^$ regex and then redirects to path/to/file.
That rule goes after the trailing slash one so with or without the slash, it gets added and only then it gets redirected.

Redirect domain to another domain in Meteor

I have two domain names, one which I've been using for a long time (blainehansenpianostudio.com), and another simplified one I'm now using (blainehansenpiano.com). I'm hosting with Digital Ocean, and my DNS is set up so that both domains point to my droplet, and both show up correctly with my site.
However, I want blainehansenpianostudio.com (the longer, more annoying one) to completely redirect to blainehansenpiano.com, but currently it just acts as an alias, showing the same site but also keeping its annoyingly long url.
The only things I've been able to dig up about http redirection are this meteorpedia article and this stackoverflow question. Neither of these seem to be taking into account the existence of a secondary domain, and are using the in-app routing system. That doesn't seem to be the correct solution, since the redirect should be happening even before the bundle is sent right? I don't want a bunch of extraneous redirects happening within my app.
Also, the SO question has this line:
The easiest way to achieve this is to put the redirect in middleware:
which doesn't mean anything to me. Where is "middleware"?
How do I go about accomplishing this? I feel like I need to change something in the server setup, but I deployed with Meteor Up, which doesn't mention anything about redirects, and am not sure where the server config I need even is.
Thanks in advance!
Update
I tried putting the following code in my lib/router.js file, just to test things out and see if the router is the "middleware" in question:
WebApp.connectHandlers
.use(function(req, res, next) {
console.log(req);
console.log(res);
console.log(next);
next();
});
but it absolutely wasn't. It just broke the router.
Possible (but messy) Solution
Putting this client-side redirect code into main.js:
if (window.location.href.indexOf("blainehansenpianostudio") > -1) {
window.location = "http://blainehansenpiano.com";
}
works, but it seems to lag for a moment after the redirect is made. It seems to me that this is triggering two entirely separate server requests, which is not at all ideal.
For a meteor app, you can use a the javascript to do a conditional redirection. An example below:
<script type="text/javascript">
<!--
function Redirect() {
if(window.location.href.indexOf("blainehansenpianostudio") > -1){
window.location="http://blainehansenpiano.com";
}
}
//-->
</script>
Are you using any other reverse proxy in front, like Apache, or Ngnix? If so, there can be better ways to achieve this.
If you install Ngnix (which is the cleaner way) for server side redirects, then you may include a new server block for performing the redirect. An example is below:
server {
#implemented by default, change if you need different ip or port
#listen *:80 | *:8000;
server_name blainehansenpianostudio.com;
return 301 $scheme://blainehansenpiano.com$request_uri;
}
In your case, you might choose to hard code the $scheme to http. $request_uri part ensures that the original request URI is included in the redirect response.
To set up nginx, I would also suggest the use of link provided by #Steffo
I use nginx in front of the meteor app (also for SSL termination - I saw that you have a sign-in button on the site, so you maybe want SSL) and it runs also on DO. Use a single nginx instance to accept requests for both domains and reverse-proxy them to a single meteor instance. I wouldn't use redirects inside the meteor app as this could easily interfere with SSL setup
server {
listen 443 ssl;
server_name www.blainehansenpiano.com;
ssl_certificate /etc/ssl/blainehansenpiano.crt
(... SSL stuff )
location / {
proxy_pass http://meteor_localhost-OR-remotehost:3000;
(... some web socket setting ...)
}
}
and also the longer name pointing to the same meteor instance
server {
listen 443 ssl;
server_name www.blainehansenpianostudio.com;
ssl_certificate /etc/ssl/blainehansenpianostudio.crt
(... SSL stuff )
location / {
proxy_pass http://meteor_localhost-OR-remotehost:3000;
(... some web socket setting ...)
}
}

301 URL Redirect with arguments without htaccess or php

How do I redirect http://olddomain.com/page to http://newdomain.com/page
The old domain is using namecheap's dns. Currently, I have setup a 301 URL redirect on olddomain.com and www.olddomain.com to www.newdomain.com. However, visiting olddomain.com/page takes me to www.newdomain.com instead of www.newdomain.com/page.
Is there a way to do it without using htaccess or php?
use webmaster tool. Thats is easy. We normaly use server side programming, ip redirect. But that is very easy and convenient.

how to get facebook profile image real url in https

I am wondering if there is a way to get facebook user profile image's real url in https.
Like I use https://graph.facebook.com/20926460/picture to get a the profile image,
It will redirect to http://profile.ak.fbcdn.net/hprofile-ak-snc4/41539_20926460_5421452_q.jpg.
Is there a way to get the "https" version of the second url? or is the url existing?
This might have changed in the docs since you last looked, I know everyone got excited about https after that snooping tool came out.
"If you need a picture to be returned over a secure connection, you can set the return_ssl_resources argument to 1: https://graph.facebook.com/xx_userid_xx/picture?return_ssl_resources=1."
Hopefully that won't redirect you.
Update 10 sept 2012
https://graph.facebook.com/20926460/picture now redirects to https urls.
You can just replace http by https in the target url but keep in mind that it is only temporary and may time out.
there is also no valid ssl certificate, but if you ignore that, the file will be served.
if you need a valid certified https url for pictures you need to set up a proxy script on your server that passes through the file.
edit:
as for your comment here is an example of what i meant by "proxy script".
you can put it on your server and request it with whatever protocl/scheme you like.
just like it was a local picture. you should probably validate the mime type. do some error handling and prevent injections etc. but just to give you ap icture:
<?
header("Content-Type: image/jpeg");
echo file_get_contents('https://graph.facebook.com/'.intval($_GET["id"]).'/picture');
fyi i put the int cast there to prevent injection hacking.
script is untested but should work as file_get_contents will follow redirects.

IIS6 - How do I redirect users to another site for every page with a few exceptions?

I have a website setup in IIS 6, let's say it's called http://www.this.com.
I have setup a redirection for this website to http://www.that.com which maintains the directory structure and query parameters as follows:
http://www.that.com$S$Q - using the option "The exact URL entered above"
This works great, whenever someone requests, for example:
http://www.this.com/subfolder/page.aspx?Id=1
then they end up at:
http://www.that.com/subfolder/page.aspx?Id=1
Now, I have one page, actually a handler, http://www.this.com/image.axd, which I do not want to redirect.
What is the syntax for that? I've read the Redirection Using Wildcards section here, but I can't work out how to do what seems to be something straight forward.
Note that image.axd is a handler so I can't just "right click" on it and set the redirection properties as it doesn't physically exist.
I also have a couple of other pages in subfolders which I do not want to redirect, for example:
http://www.this.com/subfolder/donotredirectthispage.aspx
Any help would be appreciated.
Edit: A couple of people have mentioned using ISAPI_Rewrite, for which I'm grateful, but I really don't want to introduce another complexity into the website configuration. IIS seems to imply I can acheive what I want using the ! and 0 through 9 variables.
Is it really not possible to do this using IIS?
My current workaround is to set the redirection properties on ALL folders and pages that I want to redirect except those I do not, but this is a management nightmare.
You could implement a custom error page for the page not found error (404) that does the redirection for you. You'd turn off the redirection in IIS. Build the logic for the redirection in your custom error page. Then configure your web site so that 404 errors redirect to your error page.
If you can install software on your IIS server, I'd recommend using a tool to rewrite your request URLs.
For IIS 6.0 I've used ISAPI_Rewrite and it works really well. It's lightweight and very configurable. There's a "Lite" version available for free and will support your requirements.
You configure the program using a text file containing rules that match HTTP requests and then write actions to perform once a rule is matched. Your instance would probably require a general redirect rule (similar to the one in IIS) and rules for your exceptions.
You should look into the possibility of using a header rewrite module, for example ISAPI_rewrite. There is a free "lite" version available that is enough for your needs.
What this can do for you is the following: Before actual pages are executed on the server, the Request headers are rewritten (or HTTP 301/302 redirects are issued) based on a configurable set of rules. The underlying server sees the remaining requests as if the client really made them in that fashion.
The following rules would leave image.axd requests alone, while redirecting everything else.
# image.axd stays unchanged ("L" is the "last rule" flag)
RewriteCond Host: www.\this\.com
RewriteRule ^.*?\bimage\.axd\b.* $0 [L]
# all requests that have not been stopped by an earlier rule
# end up here ("RP" is the "permanent redirect" flag)
RewriteCond Host: www.\this\.com
RewriteRule .* http://www.that.com$0 [RP,L]