Need help with redirecting

PLEASE help us help you by writing a good post!

Hi,

I have DNS Setup on a domain I bought from GoDaddy - https://rejaurrahman.co.uk/.

I need help with redirecting https://paypal-comparison-table.netlify.app/ to https://rejaurrahman.co.uk/projects/paypal-comparison-table/

I tried doing it using _redirects in the bitbucket repository but it did not work.

How can I go ahead and do this and what exatcly do I need to write to have the URL redirecting.

Ronny

Hi, @Ronny. No redirects are being detected:

https://app.netlify.com/sites/paypal-comparison-table/deploys/5edd3ec3c6c0580008362e18

Please make sure to put the _redirects file in the publish directory and not the build directory. If that is done and they still don’t work, please let us know.

Hi @luke,

Thank you for the reply. Really appreciate it.

I removed the _redirects when I added the message.

I have added _redirects file to the repository.

I attached a screenshot of the code I added to the _redirects file.

Hope to hear from you soon.

Ronny

Hi, @Ronny, the redirects are working now when I test:

$ curl -svo /dev/null https://paypal-comparison-table.netlify.app/foo  2>&1 | egrep -i '< (http|location)'
< HTTP/2 301
< location: https://rejaurrahman.co.uk/projects/paypal-comparison-solutions/

That redirects because there is no page/file at the path /foo. This would not redirect if one of these two files exists in the deploy:

  • /foo.html
  • /foo/index.html

If one of those file did exist, the URL would not redirect because the rule isn’t “forced”.

If you want a redirect to apply even when the page/file does exist, then make it a “forced” rule adding a “!” to the status (by specifying 301 the status code was blank). (301 is the default. All other status codes must be defined.) For example:

/    https://rejaurrahman.co.uk/projects/paypal-comparison-solutions/   301!

This would force the redirect even though there is a file at /index.html.

Also, do you want to do a 301 redirect or a 200 status to proxy? If you use a 200, Netlify will proxy if the files/pages don’t exist at Netlify. Again, you can also use a 200! forced rule to always proxy.

For example:

/    https://rejaurrahman.co.uk/projects/paypal-comparison-solutions/          200!
/*   https://rejaurrahman.co.uk/projects/paypal-comparison-solutions/:splat    200!

This would never show any deployed files at Netlify and alway proxy the site to the content hosted at the second URL.

Also, if you want the domain itself to point to Netlify, there is external DNS and Netlify DNS. I recommend starting with external first DNS if you are just testing.

I’m not recommending any particular solution above, just showing what is possible. There is more about redirect options in our documentation here. ​Please let us know if there are other questions about any of this.

Hi @luke,

I just updated the _redirects file and added 301! at the end of all three lines.

But the page now goes to my portfolio link https://rejaurrahman.co.uk instead of https://rejaurrahman.co.uk/projects/paypal-comparison-solutions/

How can I redirect it to the url I want.

Also N.B. there was nothing in /projects/paypal-comparison-solutions/

Ronny

Hello @Ronny, it looks like you have the following rule on the site you are redirecting to:
“/* https://rejaurrahman.co.uk”. This redirects all paths to the root. You’ll want to add a splat, like “/* https://rejaurrahman.co.uk/:splat” so that the path is preserved. Let me know if that helps.

Hi @Dennis,

I updated _redirects on my portfolio.

So nows that preserved. So when I click on the url now on netlify it redirects.

But now I am getting the error message -

" This page isn’t working
rejaurrahman.co.uk redirected you too many times. "

What do I need to do next in order for it to display the page on the redirect?

Ronny

This rule will create an infinitely loop of redirects:

/* https://rejaurrahman.co.uk/:splat

This is because the rule exists on this the site with this subdomain. It is being redirected back to itself.

So, if you put this rule on this paypal-comparison-table.netlify.app, then this URL:

https://paypal-comparison-table.netlify.app/projects/paypal-comparison-solutions/

would then be redirected to this URL:

https://rejaurrahman.co.uk/projects/paypal-comparison-solutions/

However, this rule is on this site (rejaurrahman.co.uk) not a different site. So this rule redirects this URL:

https://rejaurrahman.co.uk/projects/paypal-comparison-solutions/

to this UR:

https://rejaurrahman.co.uk/projects/paypal-comparison-solutions/

They are the same URL. This is an infinite redirect.

Would you please give real world examples of a starting URL and what URL that starting URL should redirect to? For example:

This starting URL:

https://paypal-comparison-table.netlify.app/

Should redirect to this URL:

https://rejaurrahman.co.uk/projects/paypal-comparison-solutions/

Note, this redirect above is already working. It is just that there is also a rule at the rejaurrahman.co.uk site which then creates an infinite loop.

Finally, there is the issue that there is no page at /projects/paypal-comparison-solutions/ on the rejaurrahman.co.uk site. Even if the infinite loop wasn’t happening, there will still be a 404 not found after the 301 redirect. I’d expect the redirect to target a URL which isn’t a 404.

Are you trying to display a third site at the https://rejaurrahman.co.uk/projects/paypal-comparison-solutions/ URL? If so, what third site should be shown there?

Hi @luke,

So based off your recommendations above I removed the _redirects file in my portfolio link https://rejaurrahman.co.uk.

I have added the code in the _redirects file for my paypal repository.

On my repository linked to this URL - https://rejaurrahman.co.uk I added an index.html in the following path /projects/paypal-comparison-solutions directory.

I have updated the _redirects file on https://paypal-comparison-table.netlify.app/

But its not redirecting to https://rejaurrahman.co.uk/projects/paypal-comparison-solutions/

Could you tell me what I am doing wrong.

Ronny

Hey Ronny,

I’ve just clicked https://paypal-comparison-table.netlify.app/ and been taken straight to https://rejaurrahman.co.uk/projects/paypal-comparison-solutions/. Can you confirm that this is the case for you?

Hi @luke @Dennis @Pie,

Thank for your support with fixing this issue.

I was able to fix this.

I added a sub domain to the files which fixed the issue.

Ronny