5

I've been working on a website for a couple of months and it started to get some viewership after making improvements to SEO, while it was still accessible only through a .heroku.com domain. I thought to myself that it was time to purchase a .com domain on namecheap, since that will make the site seem more legit and might lead to more clicks.

I finished the setup and my site can both be found at example.com and example.herokuapp.com. At first all of the search results in google still lead to the .herokuapp.com site and I was on the first page for many queries that I care about. But now my page is nowhere to be found. I believe this might be because google sees this as duplicate content and punishes me harshly for it.

I basically want all of the links in google to lead to the regular .com site and not have the herokuapp.com site accessible anymore or completely hide it from all search engines. I stumbled upon a few possible solutions, but none of them seem very clean or practical since my site already consists of over 400 pages. (How to get rid of Heroku App domain in the search resutls)

What would be the best way to go about this ?

Stephen Ostermiller
  • 98,758
  • 18
  • 137
  • 361
Gitschi
  • 61
  • 3
  • 1
    What isn't practical about canonical tags? They can usually be implemented programatically so you are not putting them in by hand one at a time across 400 pages. – Stephen Ostermiller Apr 25 '18 at 09:10
  • As for penalties for duplicate content, see What is duplicate content and how can I avoid being penalized for it on my site?. When Google detects duplicates it will usually choose one or the other to index. It rarely issues penalties. – Stephen Ostermiller Apr 25 '18 at 09:11
  • Changing your domain name like this has long introduced SEO headaches and traffic drops. If possible when changing your domain, you should use Google's change of address tool in Search Console: https://support.google.com/webmasters/answer/83106?hl=en – Stephen Ostermiller Apr 25 '18 at 09:13
  • Thank you for the great advice @StephenOstermiller and sorry for the late reply, It took a while to read through everything. The 301 Redirect that is mentioned in the "Google change of address tool" you linked me to is pretty much what I was looking for, however I'm having a hard time implementing it. It would be an easy task if my example.com and example.herokuapp.com would be powered by a different code-base. But since they both run on the same code, I can't just replace all the res.render requests with res.redirect(301, "xxx"); Btw. I'm using Node.js with the express library. – Gitschi Apr 26 '18 at 13:20
  • 1
    You may have access to the host name programatically under Heroku. Something like if (hostname=='example.heroku.com') res.redirect(301, "xxx"); That may not be available, which is why the canonical links are recommended in the answers to How to get rid of Heroku App domain in the search resutls – Stephen Ostermiller Apr 26 '18 at 13:24
  • Thank you so much @StephenOstermiller . I just tried it out using req.hostname and req.url, which seems to work perfectly. Now I just gotta implement it on all the pages. – Gitschi Apr 26 '18 at 13:43
  • 1
    If you could put your code in as an answer to your own question, it would probably help other people. – Stephen Ostermiller Apr 26 '18 at 14:25

1 Answers1

1

Finally got it working thanks to @Stephen Ostermiller's great advice.

The following solution will work if your back-end is running on Node.js with Express. First we will create a 301 redirect for all the necessary pages. Here is the code for the about page as an example:

/// About Page //// 
router.get("/about", function(req, res){
    const host = req.hostname;
    const url = req.url;
    if(host === "example.herokuapp.com"){
        res.redirect(301, "http://www.example.com" + url);
    } else{
        res.render("about");
    }
});

It is also just as easy to implement for get requests that have to complete a query within your database and pass a variable:

/// Kanji Index Route///
router.get("/", function(req, res){
    /// Get all kanjis from db///
    Kanji.find({}, function(err, allKanjis){
        if(err){
            console.log(err);
        } else {
            const host = req.hostname;
            const url = req.url;

            if(host === "example.herokuapp.com"){
                res.redirect(301, "http://www.example.com" + url);
            } else{
                res.render("main/kanjis", {kanjis : allKanjis});
            }
        }
    });
});

the req.url seems to only grab the last part of the path, so make sure to keep that in mind when typing out the route for your redirect.

After setting up all of the 301 redirects, follow the guide on how to use Google Change of Address Tool.

It will take a while for google to update, so I cannot confirm the results as of yet. But I believe this will solve the issue.

Gitschi
  • 61
  • 3