I tried using the following code to create a redirect function. It works for absolute URLs, but failed for relative URL based on Joomla's root folder. It tries to redirect me to a wrong path f:wampwwwWebsiteName/index.php (the slashes in paths are gone) giving me a 404 error.
May I know how I can fix the code so that it won't remove the the slashes in JPATH_ROOT so that a user can input a relative path target?
Below is the code. Thank you.
echo 'window.location.href="' . $url . '";';
echo '<meta http-equiv="refresh" content="0;url=' . $url . '" />';
that's not how to do a redirect. You need to issue a Location header with the header() function.
You also confuse filesystem paths and URLs. You cannot redirect people to a local path on your server. If anybody could browse your whole server, that would be quite insane, wouldn't it? You need a URL. I think JURI::base() is what you're looking for.
June 27th, 2013, 05:07 AM
for redirecting the page use above code.
June 27th, 2013, 05:09 AM
After using a header() redirect, make sure to use the die() function.