I have a problem: I want to redirect via JavaScript to a directory above. My code:
location.href = (location.href).substr(0, (location.href).lastIndexOf('folder'));
The URL looks like this:
example.com/path/folder/index.php?file=abc&test=123&lol=cool
The redirect affect just this:
example.com/path/&test=123&lol=cool
But want to have this:
example.com/path/
How could I do that?
Click the URL Redirects tab. In the upper right, click Add URL redirect. In the right panel, select the Standard or Flexible redirect type. A standard redirect is used to redirect one URL to another.
It is quite simple to do a page redirect using JavaScript at client side. To redirect your site visitors to a new page, you just need to add a line in your head section as follows.
You can use the attr() function of jQuery to redirect a web page as shown below: var url = "http://google.com"; $(location). attr('href',url);
Answer: window. location='http://www.newlocation.com';
You can do a relative redirect:
window.location.href = '../'; //one level up
or
window.location.href = '/path'; //relative to domain
If you use location.hostname
you will get your domain.com part. Then location.pathname
will give you /path/folder. I would split location.pathname
by / and reassemble the URL. But unless you need the querystring, you can just redirect to ..
to go a directory above.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With