Tuesday 28 August 2018

Header redirects to the page that does not exist?

I have this strange behavior, PHP headers act differently on webserver and localhost.

Example
On web hosting function
header("Location: /content/".$page['url_language']."/".$page['direction']."/".$w['id']."/")

redirects to index.php and the /content/".$page['url_language']."/".$page['direction']."/".$w['id']."/" are send as parameters.
But then i do the same on localhost and my browser redirects to page /content/".$page['url_language']."/".$page['direction']."/".$w['id']."/"
That does not exist, not the index. How this happens, there is no .htaccess on web server and localhost to change the settings. Maybe I missing some settings, any suggestions?

The HTTP/1.1 ask for an absolute URI with the parameter "location:". Some explorer accept relative paths, but your problem may come from here.
If it's an absolute path on the server, his configuration may be different from your local file. Check if /content is really in the root of the server (and not in a /www or thing like that).
Here a little code you could use to test your global variables.
<?php
/* Redirection to an other webpage in the same file */
$host  = $_SERVER['HTTP_HOST'];
$uri   = rtrim(dirname($_SERVER['PHP_SELF']), '/\\');
$extra = 'mypage.php';
header("Location: http://$host$uri/$extra");
exit;
?>`

1 comment:

  1. Nice articel about HEADER REDIRECTS TO THE PAGE THAT DOES NOT EXIST? , This article help me very well. Thank you. Also please check my article on my site Know All About Htaccess Tutorial. In link article we will learn about htaccess File.

    ReplyDelete