301 redirect to a proxy 200 redirect

Hello,

I have two separate netlify sites:

- 1 for my main website (prettybar.co > prettybar.netlify.com)
- 1 for the blog (prettybar.co/blog > prettybar-blog.netlify.com)

My redirects for the sites are:

- prettybar.netlify.com:
https://prettybar.netlify.com/* https://www.prettybar.co/:splat 301! /blog/* https://prettybar-blog.netlify.com/:splat 200

- prettybar-blog.netlify.com:
https://blog.prettybar.co/* https://www.prettybar.co/blog/:splat 301!

Problem:

My problem is that I don’t know how to redirect the domain prettybar-blog.netlify.com to prettybar.co/blog since prettybar.co/blog has a 200 redirect (proxy) to the other netlify sites prettybar-blog.netlify.com

So if I add a 301 redirect from prettybar-blog.netlify.com to prettybar.co/blog, I have a “too many redirects” error.

I would like to do that to avoid a duplicate content from Google (+ assets are not found with this url)

How can I do that? Thank you

Hey, welcome to the forum :slight_smile:

It looks like you have one domain name, prettybar.co, and then you want two subdomains of that:

  • www.prettybar.co with the main site, and if users go to /blog/, you want to preserve this URL while pulling blog posts from your other site
  • blog.prettybar.co with the blog

Is that right? Your setup and _redirects on prettybar.netlify.com seem reasonable to me. One thing that might work is creating a domain alias for prettybar-blog.netlify.com by going to Domain Management > Custom Domains > Add Domain Alias and putting blog.prettybar.co there. More on domain aliases here:
Sites with multiple domains | Netlify Docs

Then, I think you’re _redirects file for prettybar-blog.netlify.com would look like:

/*  https://www.prettybar.co/blog/:splat 301!

Want to give that a shot? If you keep getting that error, come back and let us know so we can dig in a bit more.

One more resource for you that may be worth checking out!

Hello,
(I can’t put links because “Sorry, new users can only put 6 links in a post.” :slight_smile: ).
I have also tried setting up redirects as instructed (by @jen ) but it doesn’t work.
My main site is myOwnDomain => netlifyDomain (with custom domain and redirections from netlify to my own).
My blog site is blogMyOwnDomain => blogNetlifyDomain (same redirects).
With

# 360demain.netlify.app netlify.toml  
# Redirections
  [[redirects]]
    from = "https://360demain.netlify.app/*"
    to = "https://360demain.com/:splat"
    status = 301
    force = true

  [[redirects]]
    from = "http://360demain.netlify.app/*"
    to = "http://360demain.com/:splat"
    status = 301
    force = true
	
# https://answers.netlify.com/t/support-guide-can-i-deploy-multiple-repositories-in-a-single-site/179
	[[redirects]]
    from = "/blog/*"
    to = "https://360demain-blog.netlify.app/:splat"
    status = 200
    force = true

Request myOwnDomain/blog lead to blog.myOwnDomain (but I want to continue on myOwnDomain/blog…).
when I add

# 360demain-blog.netlify.app netlify.toml   
 # Redirections
  [[redirects]]
    from = "/*"
    to = "https://360demain.com/blog/:splat"
    status = 301
    force = true

On blogMyOwnDomain’s netlify.toml, I have a “too many redirects” error.
How can I fix that ?

My goal is to prevent blogNetlifyDomain or blogMyOwnDomain from being indexed. I would like to keep the unique url myOwnDomain/blog/* for this git repository.

Thanks!

Hi @colinlemaitre

This is expected behaviour.

In testing a ways to overcome this (there are methods mentioned throughout these forums) the best I have figure out it the following:

Don’t publish the site you are proxying to at the domain root. So if you are using /blog as the path, publish the original site to /blog (e.g. 360demain-blog.netlify.app/blog)

On the proxied site (e.g. 360demain-blog.netlify.app) instead of having a redirect like

/*     https://example.com/blog/:splat   301!

or

[[redirects]]
  from = "/*"
  to = "https://example.com/blog/:splat"
  status = 301
  force = true

replace with two redirects

/blog/*    /blog/:splat     200
/*     https://example.com/blog/:splat   301!

or

[[redirects]]
  from = "/*"
  to = "https://example.com/blog/:splat"
  status = 200

[[redirects]]
  from = "/*"
  to = "https://example.com/blog/:splat"
  status = 301
  force = true

The first allows anything on the blog path through while redirecting everything else to redirect. As there is no content on the homepage, there is nothing to get indexed. Also add a canonical link (e.g. <link rel="canonical" href="https://example.com/blog/">) and refresh <meta> to the (otherwise) blank /index.html on the blog site.

Hope this makes sense.

1 Like

Thank you very much !
It was difficult to figure out how to adapt this suggestion to my static site generator (Hugo) but it’s now ok I believe:
blog.360demain.com => returns a 404 error
blog.360demain.com/blog is accessible but not indexed by search engines (and I can manage it via /admin with Netlify CMS for example :slight_smile: on blog.360demain.com/admin).
The public site 360demain.com/blog is operational.
Perfect !
Now we have to code…