开发者

Heroku subdomain duplicate content? How to redirect to domain?

开发者 https://www.devze.com 2023-02-19 14:58 出处:网络
Google has indexed my Heroku app subdomain: myapp.heroku.com Is it duplicate content? How should I red开发者_开发百科irect myapp.heroku.com to mydomain.com?According to Heroku docs for custom domain

Google has indexed my Heroku app subdomain: myapp.heroku.com

Is it duplicate content?

How should I red开发者_开发百科irect myapp.heroku.com to mydomain.com?


According to Heroku docs for custom domains, you could do it like so:

class ApplicationController
  before_filter :ensure_domain

  APP_DOMAIN = 'myapp.mydomain.com'

  def ensure_domain
    if request.env['HTTP_HOST'] != APP_DOMAIN
      # HTTP 301 is a "permanent" redirect
      redirect_to "http://#{APP_DOMAIN}", :status => 301
    end
  end
end

I use this method and it works fine. Note that since the redirect returns a 301 http status (a permanent redirect) your site won't be penalized for duplicate content.

The 301 status is the only point missing in Markus' solution, but I think it is an important one if your concern is with SEO.

Edit: Something that's not on the docs and I forgot to mention - you should exclude the environments you don't want the redirect applied to. You could change the if statement to something like:

if request.env['HTTP_HOST'] != APP_DOMAIN && ENV["RAILS_ENV"] != 'development'


Use the Heroku add-on custom domains:

heroku addons:add custom_domains:basic
heroku domains:add www.myapp.com
heroku domains:add myapp.com

In addition, you have to take some configuration steps at the admin interface of your domain provider. You need a CNAME to proxy.heroku.com and three A-RECORDs to the Heroku IPs. You find this in the Heroku Docs.

Edit to respond to another answer below. You can redirect myapp.com to www.myapp.com in your routes.rb:

 constraints(:host => /^communityguides.eu/) do
    root :to => redirect("http://www.communityguides.eu")
    match '/*path', :to => redirect {|params| "http://www.communityguides.eu/#{params[:path]}"}
  end


I suggest using rack-canonical-host to redirect Heroku's subdomain to your custom domain.


rel canonical is one possibility just put <link rel="canonical" href="http://mydomain.com"/>, <link rel="canonical" href="http://mydomain.com/page"/>, ... on your app pages.

see http://www.google.com/support/webmasters/bin/answer.py?answer=139394

google will treat the URL in the canonical element as the right ressource for that specific page.


The first answer goes part way to solve the problem but introduces a new problem.

If you add www.myapp.com and myapp.com you will then need to take care of redirecting one of these to the other inside your application - so if you choose www.myapp.com as your primary you want to check if the requested URL IS NOT www.myapp.com and redirect the request to www.myapp.com - this will then cover redirects requests coming to myapp.com and myapp.heroku.com correctly. There's an example by Heroku on their docs here.

Also, you need to get rid of the content that Google has already indexed on the Heroku domain. You'll need to use Google WebMaster tools to change the domain to www.myapp.com - it's a relatively simple process once you're logged into webmaster tools


first of all if you do not want your myapp.heroku.com to be indexed simply by adding robot meta tag in your header and give the value to "nofollow".

and for redirection just add another meta tag refresh:

<meta http-equiv="refresh" content="2;url=http://www.heroku.com/">  

the content value is in seconds, the example above will direct visiotrs in 2 seconds to your main page.

hope it helps


Use the hide_heroku gem, it uses X-Robots-Tag HTTP headers to prevent search engines from indexing anything under *.herokuapp.com

0

精彩评论

暂无评论...
验证码 换一张
取 消