_redirects not working

I have followed everything exactly from the documentation video and I have tried looking online for what I am doing wrong but I have found no answers. Here’s the video:

Here’s my github of the project:

and the actual website thats live right now:
https://www.bobthedentguy.com

I have tried talking to netlify support but I have been passed around to 3 different people that have each not solved my problem or my understanding of it. I am at my wits end trying to understand why something so simple is giving me so much trouble. Any help is appreciated.

Do you have pretty URL’s turned on?

I don’t know what that is actually. Is that a netlify thing?

Yes. If you go into your dashboard and build & deploy section. Image below from docs.

Please check this out, this may be whats causing your headache.

1 Like

that works and is a lot better than what was there before. I’m going to keep that there, but what do I do about https://bobthedentguy.netlify.com/ redirecting to https://www.bobthedentguy.com/ ? Also, the urls still have the html/ folder in them. What can I do about that?

For the netlify subdomain redirect, you will need to go into your DNS and make the desired adjustments. Link below. If you have trouble with this, please open a new topic for help in the dns category.

As for the html redirect, something like this should work without the .html appended (note, not tested)

  /html/index / 200!
  /html/about /about-bob-the-dent-guy 200!
  /html/portfolio /portfolio 200!
  /html/contact /contact-bob-the-dent-guy 200!

I’m going to put the _redirects file here for discussion:

/html/index.html / 200!
/html/about.html /about-bob-the-dent-guy 200!
/html/portfolio.html /portfolio 200!
/html/contact.html /contact-bob-the-dent-guy 200!
https://bobthedentguy.netlify.com https://www.bobthedentguy.com/html/index.html 301!
  • [line1] proxy rewrites the path /html/index.html to the root which means the path /html/index.html will stay in the address bar and show the /index.html content (incorrect?)
  • [line2] proxy rewrites the path /html/about.html to /about-bob-the-dent-guy which means the path /html/about.html will stay in the address bar and show the /portfolio/index.html content (incorrect?)
  • [line3] proxy rewrites the path /html/portfolio.html to /portfolio which means the path /html/portfolio.html will stay in the address bar and show the /portfolio/index.html content (incorrect?)
  • [line4] proxy rewrites the path /html/contact.html to /contact-bob-the-dent-guy which means the path /html/contact.html will stay in the address bar and show the /contact-bob-the-dent-guy/index.html content (incorrect?)
  • [line5] redirects https://bobthedentguy.netlify.com to https://www.bobthedentguy.com/html/index.html

Can you define what you want to happen?

In example, give the condition of what the user will type into the address bar then what will happen for each use case.

User types in address bar: /html/index.html
Result: <explain that here>

Explanation of 200

The 200 is used for proxy rewrites and does not redirect to the result path. A 200 tells the CDN to keep the path in the address bar, but show the target path as the response.

I copy and pasted your code but the pages return a 404. i changed the html folder to “bobsite” so it’s cleaner than html/about etc. I added the pretty url feature as described to me by another, but when I try to add the 200! rewrites to the new pretty url paths i still get 404. When a user is on the home page and clicks the ABOUT tab I want the new page to be bobthedentguy.com/about. But the rewrites never seem to work. I added https://bobthedentguy.netlify.com https://www.bobthedentguy.com/ 301! to redirect the netlify subdoiam to the main domain for SEO purposes but that doesnt work either. The github has been updated accordingly

What am I doing wrong?

Let’s just solve one issue at a time. If you are leaving on pretty url’s then try this.

All:

/bobsite/about  /about 301
/about /bobsite/about.html 200
/bobsite/portfolio  /portfolio 301
/portfolio /bobsite/portfolio.html 200
/bobsite/contact  /contact 301
/contact /bobsite/contact.html 200

The above worked when I forked your repo and tried it with the current structure.

Explanation (using pretty urls)

The first redirect is the pretty url path (rewritten by the CDN) redirected to the simple path (proxy) that really does not exist.
The second proxy rewrite (200) is rewriting the url path and making a proxy to the static content.

1 Like

that worked! Thank you. I have no idea what that code means but I’ll try and replicate it for my other sites. No we just need to redirect the .netlify subdomain to the main domain

Is there a reason you are storing your paths and files like that?

If using pretty urls, you could just store them in the folders of the pretty paths.

index.html
about/index.html
contact/index.html
portfolio/index.html

Then you would not have to use redirects also, but not sure how you are creating your site. Just a thought.

1 Like

I have image, js, html and css files in their own folders for cleaner file management and make it easier to find the ones I’m looking for. I created the site just using html css and javascript. No frameworks or anything. I have a client that has like 20+ html pages and accompanying css files so it will be messy if I don’t put them in files.

big thank you from Netlify support to @talves and @garrettbland for workshopping this. Glad it’s working now :muscle:

3 Likes

No problem, but doing these proxies will get confusing later if you ever stop using absolute paths to your assets. This works, because the asset paths are where they are expected.

Your setup is simple, but could get confusing when paths go bad.

1 Like

Thank you for you help, I would never have figured this out without you. Why do we need the 301’s in there? Just asking so I can better understand what is happening and why. And when I type bobthedentguy.netlify.com it doesn’t redirect to bobthedentguy.com. Do I need to do something different there too? I don’t want google to penalize the main domain for duplicate content

The 301’s are for redirect to the path you wanted. The 200’s are only rewrites of the fake path that does not exist.

Now add this at the top:

https://bobthedentguy.netlify.com/* https://bobthedentguy.com/:splat 301!

This will redirect any path at the netlify domain to the primary domain if someone tries it. It will also tell google to redirect permanently from now on and not see it as a duplicate.

Final

Note: redirects will go in order, so you want to make sure you capture the condition ahead of the resulting paths.

https://bobthedentguy.netlify.com https://bobthedentguy.com 301!
https://bobthedentguy.netlify.com/* https://bobthedentguy.com/:splat 301!

/bobsite/about  /about 301
/about /bobsite/about.html 200
/bobsite/portfolio  /portfolio 301
/portfolio /bobsite/portfolio.html 200
/bobsite/contact  /contact 301
/contact /bobsite/contact.html 200

Apologize ahead of time for all the edits, typing too fast and not paying attention.

1 Like

no problem, I’m really grateful for you time in the matter. I tried putting the domain redirect at the top just as you said but it still doesn’t redirect. Not sure hats going on. Does it take a while for it to work?

No, should work as soon as it deploys.

Are you sure the domain is on this site and not another. I have not seen this issue before.

OR could it be that the primary domain is www.bobthedentguy.com

i did everything you laid out at the .netlify domain does not redirect to the primary domain. still trying to figure that one out