nginx wildcard redirection configuration - redirect

I have a web application that is running on myhost.com
When a user clicks on any of the buttons on the page I want to redirect them to the same page hosted on a different server. So for example I want myhost.com/x/happy to redirect to uathost.com/x/happy
I am trying to use wild card so that every /x/* page is redirected appropriately.
I tried to use the below configuration but I still get a 404 from myhost.com when clicking on any of the buttons since myhost.com is not configured with those pages, thus my need for a redirect.
location ^~/r/ {
proxy_pass https://uathost.com/$1;
}

Well are you redirecting or proxying? The code you are showing is for a proxy to uathost.com not redirect.
For a redirect all should have to do is:
location /x {
return 301 https://uathost.com$request_uri;
}

Related

HAProxy 1.5 URL/URI Redirects to a different domain

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...

Redirect and rewrite based on domain name

What I need to get working:
I need to redirect based on the domain name from the request, and once the redirection has occurred I need to rewrite the url so that users only see that domain name in the url.
Specifics
My site currently has the domain name example.com and I have a second domain name different.com that I need to redirect traffic to a specific url. This url will switch to a different store view: example.com?___store=differentstore
The switching is working fine, but I need to figure out how to setup a rule in nginx that will watch for the different.com and then redirect to the above url but from that point rewrite the url to different.com so that those users never see example.com.
The only time I need the ?___store=differentstore is on the initial entry with different.com as the host. From that point on users won't be able to see the default view (for example.com) unless they browse to the example.com domain
What I've tried:
This is what I have tried so far and it isn't working:
server {
listen 80;
server_name www.different.com different.com;
return 301 http://www.example.com?___store=different;
if ($http_host != "www.example.com" && $http_host != "example.com") {
rewrite ^ http://different.com$request_uri;
}
Details
LEMP stack
Magento 1.7

Fiddlercore: how to block and redirect sites

Fiddler core .net api proxy server captures network traffic.
how to redirect any http/https url to another site.?
suppose if I browse yahoo.com, then proxy server should redirect to another site such as wikipedia.com. Browser should open wikipedia instead of yahoo.com.
how to block any web site.?
suppose when I hit espncricinfo.com in browser, then site must be blocked and stopped its session
These topics are well-covered in the Fiddler book and in numerous tutorials around the web.
Inside your BeforeRequest handler, add code that examines the request and returns a redirect (or an error page)
if (oSession.urlContains("whatever"))
{
oS.utilCreateResponseAndBypassServer();
oS.oResponse.headers.SetStatus(307, "Redirect");
oS.oResponse["Cache-Control"] = "nocache";
oS.oResponse["Location"] = "http://newurl/";
oS.utilSetResponseBody("<html><body>sending request elsewhere</body></html>");
return;
}

Redirect to internal URL ignored within facebook app canvas

I am new to facebook applications, so maybe I am overlooking something very simple.
I am developing this on GAE on flask framework.
This is how I have setup my facebook app. (note the https on localhost is setup through stunnel)
Everything seems to be ok, until I have to do an internal redirect to the "login".
def index(show_friends=None):
if current_user.is_authenticated():
return redirect(url_for("show_records"))
if 'fbapp' in request.args:
return redirect(url_for("login"))
else:
return render_template('index.html')
urls are set like this:
app.add_url_rule('/', 'index', view_func=views.index, methods=['GET', 'POST'])
app.add_url_rule('/login', view_func=views.login, methods=['GET', 'POST'])
This fails with the message:
The connection was reset
The connection to the server was reset while the page was loading.
Looking at the server log, it seems, the login redirect was ignored all together. Not sure why.
INFO 2013-07-14 12:15:39,026 dev_appserver.py:3105] "POST /?fbapp HTTP/1.1" 302
Any suggestions would be highly appreciated,
Wild guess... But the problem may relay on the fact that the login page sends back an X-Frame-Options header that disallow the browser to show the page inside the iframe.
If the login page ends up being the appengine login page, well... that page does return the X-Frame-Options header and cannot be loaded inside the iframe.
If this ends up being the problem, the usual solution is to have the login page loaded on a separate new window that gets automatically closed after a successful login.

Not getting $_REQUEST['signed_request']

I'm trying to pass some variables to my facebook app from the url, i.e. using GET variable app_data like facebook wants.
At some point I've stopped getting the ['signed_request'] part of the $_REQUEST. When I print_r($_REQUEST) I'm getting: ['doc'], ['user'], ['__utmz'], ['__utma'] and ['session'] values, but not signed request :(
Any ideas of why this might be happening?
Check the tab/canvas url is EXACTLY the same as required. If there is a redirect to another page, then signed request and other values will not be sent. You can check using a browser sniffer, if a call to the page responds with a 300 (301/302 etc) redirect, then you need to change to what it redirects to.
Examples:
https://example.com/ may need to be https://www.example.com/ (add www., or remove www. depending on how server is set up)
www.example.com/ may need to be www.example.com/index.php (add index.php, or the right page).
Check you are using http:// and https:// correctly in the URLs, and that https:// returns a valid page.
I've only been able to get the signed request in https://, i get no request at all in http.
Currently have a bug on FB, but no word on fixing it yet; http://developers.facebook.com/bugs/264505123580318?browse=search_4eb3ef23eb18d6649415729
EDIT:
http://SITE.com was redirecting to http://www.SITE.com, so I was loosing the request variables.
Had a similar issue, for me it was as simple as a mismatch of the app id and app secret! However in facebook developers backend I have noticed that the URLs all need to have that trailing slash!
Some browsers do redirect your request to https automatically if you have been on this particular site on https so if you are in http mode on facebook there is situation:
facebook requests http version of your app, browser redirect this request of facebook to https and POST data and thus signer_request are gone in this process...
i see this problem in chrome 23, if you delete browsin data (particulary Deauthorize content licenses) app should run back on http