T. K.
asked 02/25/21Redirect to other page if there are no parameters in url, otherwise stay at current page.
I need to redirect from my website if there are no parameters in the url with javascript, html. (redirect with html,js)
For example, if a page on my site was example.com/page and if there were parameters on the current page (e.g. example.com/page.html?code=J0eXAiOij ) then the page should stay at the current page . If there are no parameters on the current page then it should redirect to another page. (e.g. example.com/page.html - redirecting to - example.org/rejected)
Is there anyone who can help me? I'm still learning Javascript so this is tough for me.
Thanks!
1 Expert Answer
Lindsey A. answered 03/04/21
Master's Degree in Web Design, Including CSS / HTML / JS
Hi T. K. :)
You could do a 301 redirect. A 301 redirect is a permanent redirect to a different url. You could set this up with the host, and apply it to the url you want to replace.
Below, there is another way to do it by coding it on the page with the link or button. It's a simple example from W3Schools.com, which is a great resource for all types of web dev coding. This example uses a button, but you could do the same thing with a link, if that's what you're using. Just replace the "https://www.w3schools.com" with the url you want to redirect to.
Let me know if you have any questions or need help with anything else.
Have a good one! :)
Still looking for help? Get the right answer, fast.
Get a free answer to a quick problem.
Most questions answered within 4 hours.
OR
Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.
T. K.
P.S. look closely at my example because some answers are doing the exact opposite of what I want it to. It redirects if there are parameters but does not is there are no parameters. I need it to redirect if there are no parameters and stay if there are parameters02/25/21