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

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.

Related

Cloudflare redirect domain

I'm trying to redirect domainA.com to domainB.com. Both domains are managed with Cloudflare. I've tried using Page Rules for domainA to redirect all requests to domainB.com. However, I've also read that domainA needs to have DNS records of some sort through Cloudflare but I'm not entirely sure how to configure these? This redirect is the only thing I'm using domainA for, there's no content hosted on it at all.
A combination of a mock CNAME record and a Page Rule will make it.
Go to your source domain's DNS settings page.
Create a CNAME record for the # (root domain). Point it to some subdomain, it doesn't have to exist as the page rule will kick in before the DNS record resolves.
Go to your source domain's Page Rules page.
Create a new page rule redirecting all requests to your domain as necessary (choose 301/302 - whichever makes sense in your case).
Give it some time and confirm https://source-domain.com redirects to https://target-domain.com.
Repeat steps 1 - 5 for the www subdomain if you want www.source-domain.com to redirect too (which is often the case).
Set a forwading page rule 301 Redirect
from
http://domainA.com/*
to http://domainB.com/$1
In 6 steps you have new domain.
In your control panel, select the domain
Click on page rules
In 'url match' set example: (domainA.com/*)
Setting is 'forwarding url' with 302 (test) or 302 (production)
And finnaly set the new url ex: (http://domainB.com)
Save and deploy
for full documentation see this:
https://support.cloudflare.com/hc/en-us/articles/200172286-Configuring-URL-forwarding-or-redirects-with-Cloudflare-Page-Rules

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.

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.

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 redirect vs parking

I have several domain names registered, each a slight variant of each other.
E.g,
fastcar.com
fast-car.com
fastcar.co.uk
fast-car.co.uk
etc..
I don't wish to be penalized for duplicate content or spammy links by any of the major search engines.
Should I park them all directly on the main domain I wish to promote, 301 redirect them to the main domain or not use them at all?
If 301 redirects are the best option, would having two web hosting accounts be better than one?
Example:
Hosting account 1 has fastcar.com linked through the dns.
Hosting account 2 has fast-car.com, fastcar.co.uk, fast-car.co.uk linked through dns, and 301 redirects pointing to fastcar.com
Thanks
I'd 301 redirect and then specify your preferred URL:
http://googlewebmastercentral.blogspot.com/2009/02/specify-your-canonical.html