Redirect domain to another domain in Meteor - redirect

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

Related

Override single API endpoint locally

Is it possible to override a single API end-point locally?
i.e:
https://jsonplaceholder.typicode.com/todos/1
To this one:
http://localhost:3000/todos/1
But without touching others end-point like:
https://jsonplaceholder.typicode.com/movie/1
I'm trying to find a tool to do this, I also tried to use the hosts file but it work only domain by domain, not for a single API endpoint.
You can use the Map Remote function in Charles. I believe similar feature exists in other HTTP proxy tool such as Fiddler too.
First, configure Map Remote and mapping https://jsonplaceholder.typicode.com to http://localhost:3000, limit the path to /todos/*, so that it won't impact /movie/1:
Then, as Charles is trying to intercept HTTPS site, you need to enable "SSL Proxying" and add jsonplaceholder.typicode.com (Otherwise, browser will ignore the interceptor or just throw a certificate warning):
It's done. In browser, access to https://jsonplaceholder.typicode.com/todos/1 or https://jsonplaceholder.typicode.com/todos/2 will be redirected to http://localhost:/todos/1 or http://localhost:3000/todos/2 internally, while access to https://jsonplaceholder.typicode.com/movie/1 is not touched.

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

The right way to do a 301 NGINX redirect without losing backlinks

I faced an issue with the Google Dec. 2016 update, and lost 99% of my traffic (200K/day to 1K/day). As a result, I've created a new website in the same niche. Now, my goal is to transfer the DA (Domain Authority) to my new domain from the old one. However, while trying to accomplish a 301 redirect such a way
rewrite ^ $scheme://new-domain.com$request_uri permanent;
I faced another issue.
I have a lot of quality backlinks from WSJ, NYT, Wikipedia, etc., which direct to some particular pages on my old domain. If I use such a redirect, these quality backlinks now point out to the empty pages (404).
I have thousands of pages on my old domain, and I can't create so many pages one more time on my new domain.
Here are my primary questions:
1) How can I accomplish a 301 redirect without losing my old quality backlinks?
2) Is there a method to redirect all the old backlinks to my old domain to the main page of my new domain? In other words, I want to redirect all the domain authority from all the old backlinks to the main/index page of my new domain.
I use NGINX.
P.s.:I wasn't able to discover the exact answer to my question on Stack Overflow.
You have a few options, depending on a few things.
Is the old domain hosted on the same server as the new one, with all the old files accessible? If so are you interested in serving those pages still, either from the new domain or the old one, or do you just want all traffic to the old domain to land at the new one?
If its the last option it's easy, you just create two server blocks, one for each domain.
First up the old one, we'll get rid of your rewrite directive as return is more suitable and set up the first block to catch everything to old domain and send it to new domain:
server {
listen 80 default_server;
server_name old-domain.com;
return 301 https://new-domain.com/ # Everything to homepage, or:
return 301 https://new-domain.com$request_uri; # This will include the full request url
}
server {
listen 443 ssl http2;
server_name www.new-domain.com;
...
}
If you still want to serve content from the old domain you can do that too, depends on your aim.

http://www.servername & http://servername redirect to https://servername not working

We have a server called servername.com, if anyone goes to http://servername.com or http://www.servername.com we want them redirected to https://servername.com
Here's thenginx redirect block
server {
listen 80;
server_name www.servername.com servername.com;
rewrite ^/(.*)$ https://servername.com/$1 permanent;
}
http://www.servername.com is getting redirected to https://servername.com while servername.com is not getting redirected to https://servername.com
I have a seperate 443 block to handle https which works fine for https://servername.com. So if anyone goes directly to https://servername.com everything works fine. But all entries coming to servername.com or servername.com/demo are failing.
I tried separating out www.servername.com and servername.com as seperate blocks, same issue still persists.
How do I send http://servername.com or servername.com traffic to https://servername.com ?
Edit: 16th May 2017
Edited Server block as rewrite is depricated/not recommended
server {
listen 80;
server_name www.servername.com servername.com;
return 301 https://servername.com$request_uri;
}
The issue was due to DNS records getting changed on the hosting provider's side.
By default the provider doesn't allow one domain name to have 2x DNS addresses. But in this case there were 2 entries pointing to 2 locations. The entry got added on the hosting provider's end and was not pointing to the correct server or was pointing to 2 different places, they didn't take the blame and pointed out that a user must have done it on our end. However, when anyone went to https://servername.com or https://www.servername.com they landed on the correct landing page at https://servername.com, non https requests were not going anywhere in chrome but working fine with Mozilla Firefox.
Anyways, if you end up with this issue, 1st thing you can do is, check where the DNS is pointing & then fiddle with nginx/apache.

subdomain redirect to a specific port using SRV?

Lets say I have the following:
subdomain: xyz.mydomain.com
my server's public DNS: xyz.fastserver.com
when someone goes to xyz.mydomain.com I want them to be redirected to
xyz.mydomain.com:8080
I have full access to all the typical A(host), C(NAME) as well as SRV records etc, tried different configurations but cant get it to work.
Any ideas?
You did not explicitly specify it, but I assume you mean HTTP (i.e. web browsing) and not FTP, SIP, SMTP... and lots of the other protocols on the internet.
In this case what you are trying to do is not possible. DNS A/AAAA/CNAME records are only used to get an IP address, so you can not get a port with these settings. And SRV records are not used within HTTP, so you can not use it to specify the port too.
Link to previous post that goes over the difference between redirect, rewrite, and vhosts.
DNS, however, has no concept of "port" unless you make a special record (SRV) and then a special request to get that record. It is much more transparent to use one of the HTTP methods described above.