worldcomingtoanend Posted November 16, 2009 Share Posted November 16, 2009 the code below extracts a relative path and redirects the user to the corresponding content page. This works fine in my cms before publishing online but as soon as i publish my work the relative paths seem not to work anymore. this is what i get after publishing: www.cars.com/www/buses/coachescontent/index.html with a message The requested URL /www/buses/coachescontent/index.html was not found on the server this is what I need to have: www.cars.com/buses/coachescontent/index.html . my code and what I have tried. // menu entries and extraction of relative paths to content <some cms code for menus> <?php $destinationUrl="/..$destinationUrl"; ?> </some cms code for menus> // on menu click direct user to content <?php header("Location: ..$destinationUrl"); exit; ?> . I hv tried this to try and cut the /www but its not working. how do i cut the /www before buses in in www.cars.com/www/buses/coachescontent/index.html so that i only have www.cars.com/buses/coachescontent/index.html <?php $destinationUrl =substr($destinationUrl, 4); header("Location: $destinationUrl"); exit; ?> Quote Link to comment https://forums.phpfreaks.com/topic/181705-solved-help-with-php-redirect-relative-paths-absolute-paths/ Share on other sites More sharing options...
worldcomingtoanend Posted November 16, 2009 Author Share Posted November 16, 2009 by the way I have also been thinking that it might be solved like below but i am getting clueless: if ( $_SERVER['SERVER_NAME'] == "localhost" ) { header("Location: ..$destinationUrl"); } else { //i know this is wrong but i hope u get the idea of what i need to have header("Location: http://www..$destinationUrl"); } Quote Link to comment https://forums.phpfreaks.com/topic/181705-solved-help-with-php-redirect-relative-paths-absolute-paths/#findComment-958338 Share on other sites More sharing options...
chadayers Posted November 16, 2009 Share Posted November 16, 2009 Is this what your looking to do? Working example: http://code.chadayers.org/helper/3.php <? $destinationUrl = "www.cars.com/www/buses/coachescontent/index.html"; $destinationUrl = str_replace("/www/", "/", $destinationUrl); echo $destinationUrl; ?> Quote Link to comment https://forums.phpfreaks.com/topic/181705-solved-help-with-php-redirect-relative-paths-absolute-paths/#findComment-958341 Share on other sites More sharing options...
dreamwest Posted November 16, 2009 Share Posted November 16, 2009 function redirect( $url ){ if (! headers_sent( ) ){ header( "Location: ".$url ); exit( 0 ); } echo "<script language=Javascript>document.location.href='".$url."';</script>"; exit( 0 ); } redirect('http://www.cars.com/buses/coachescontent/index.html'); Quote Link to comment https://forums.phpfreaks.com/topic/181705-solved-help-with-php-redirect-relative-paths-absolute-paths/#findComment-958343 Share on other sites More sharing options...
worldcomingtoanend Posted November 16, 2009 Author Share Posted November 16, 2009 dreamwest and chadayers thank u both of u for your help... i did something like this: <?php $destinationUrl = str_replace("/www/", "/", $destinationUrl); header("Location: .$destinationUrl"); exit; ?> u r just geniouses thanks again and good day. Quote Link to comment https://forums.phpfreaks.com/topic/181705-solved-help-with-php-redirect-relative-paths-absolute-paths/#findComment-958386 Share on other sites More sharing options...
chadayers Posted November 16, 2009 Share Posted November 16, 2009 Just need to change header("Location: .$destinationUrl"); to header("Location: ".$destinationUrl); Quote Link to comment https://forums.phpfreaks.com/topic/181705-solved-help-with-php-redirect-relative-paths-absolute-paths/#findComment-958388 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.