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

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.

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

nginx wildcard redirection configuration

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;
}

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.

Can you set ads.txt to redirect to a file on another server?

I've hit a bit of a problem with creating an ads.txt file. I'm working with an advertiser, and they would like to host the ads.txt file so they can easily make changes to it.
Is it possible to set up a redirect in at
mysite.com/ads.txt
which points to something like
theirsite.com/mysite/ads.txt
If so, what would be the code to you in mysite.com/ads.txt to make the redirect work?
For those looking, I did eventually find a solution to this by editing the following line into the .htaccess (you'll need to alter the path for your own link):
RewriteRule ^ads\.txt$ "https\:\/\/theirsite\.com\/clients\/folder\/ads\.txt" [R=301,L]
Per IAB's ads.txt Specification 1.0.1 (September 2017), section 3.1 "ACCESS METHOD",
Only a single HTTP redirect to a destination outside the original
root domain is allowed to facilitate one-hop delegation of authority
to a third party's web server domain.
So you should be fine with a single redirection from mysite.com/ads.txt >> theirsite.com/mysite/ads.txt.
It is possible with restriction. You can use redirects, as many as you want within the scope of the original root domain, which is not the fact in your situation.
For a third party domain the restriction is that only a single redirect is allowed. You should check if this is the fact for your advertisers ads.txt url.
Another possible solution is:
Crawl the advertisers ads.txt and put it in your specific folder once or twice a day.
See the specification:
https://iabtechlab.com/wp-content/uploads/2017/09/IABOpenRTB_Ads.txt_Public_Spec_V1-0-1.pdf
If the server response indicates an HTTP/HTTPS redirect (301, 302, 307 status codes), the
advertising system should follow the redirect and consume the data as authoritative for the
source of the redirect, if and only if the redirect is within scope of the original root domain as
defined above. Multiple redirects are valid as long as each redirect location remains within the
original root domain. For example an HTTP to HTTPS redirect within the same root domain is
valid.
Only a single HTTP redirect to a destination outside the original root domain is allowed to
facilitate one-hop delegation of authority to a third party's web server domain. If the third party
location returns a redirect, then the advertising system should treat the response as an error. A
future version may address other delegation of authority to a third-party web server. Any other
redirect should be interpreted as an error and ignored.

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