How to redirect page which is in (php) folder?

How to redirect page which is in (php) folder?

i want to redirect from (index.php) which is outside php folder to (userpanel.php) which is in php folder.

userpanel.js

window.location.replace("/php/userpanel.php");

Problem

when i m login from (index.php) and click on login button, it show me following error.
how can i redirect to (userpanel.php) which is in (php) folder.
this is tested on localhost.

The requested URL /govn/userpanel.php was not found on this server.

I don’t even know why you’re using Javascript for this

<?php
/* Redirect browser */
header("Location: http://whatever.com/php/userpanel.php");
 
/* Make sure that code below does not get executed when we redirect. */
exit;
?>

This is just one posibility of the thousands available. Probably yours will work too if you use the full address, me thinks

I mean, if you’re login in, you’d be checking that the account exists and name and password are correct. This is a job for the PHP script, not for Javascript (exceptions made if you use Node.js but then, why would you use PHP?)

Snippet from userlogin.php

 if($row>0) {
	$_SESSION['user'] = $uname;
echo "Login Successfully";
}

Snippet from userlogin.js

    success: function(data) {
        
	$('input#uname').val('');
  $('input#upass').val('');
		
          alert(data);
          $('#disp').html(data).fadeOut(2000);
          if (data == "Login Successfully") {
            window.location.replace("userpanel.php"); // here //window.location.replace("php/userpanel.php");  is not working

          };

this is a relative link, does it exist at all? does the /php folder is a publicly (by HTTP) available path/URL?

Using PHP Header function is really easy to get the redirect working. Just make sure Nothing is outputted before the header function or it will crash.
How to redirect with PHP