开发者

Header redirects to page that doesn't exist?

开发者 https://www.devze.com 2023-01-02 15:54 出处:网络
I have this strange behav开发者_开发知识库ior, PHP headers act differently on webserver and localhost.

I have this strange behav开发者_开发知识库ior, 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;
?>`


It is possible to write Redirect Rules into the apache configuration file, your server may have a redirect rule for all urls which are not directorys or files to route to index.php and parse the string as parameters. Without knowing what the server is running on I cant tell you where the apache config file is.

Also how are you accessing the url string on the live site, you say that it parses the url string as parameters, are you using $_GET['some_var']?

Luke


Thanks for reply fellaz. I just called my web hosting support, and told that, my requests are beaing rewriten, and he sayd that yes, apache config had been edited for rewrites, after i updated my apache config with new directives, everything started to work properly, thank you jeesus – Jevgeny 0 secs ago edit

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号