Jump to content

Recommended Posts

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;

?>

 

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");        
}

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;
?>

 

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');

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.