Jump to content

PHP redirect URL confusion----hope you can help


worldcomingtoanend

Recommended Posts

1).  suppose my url is www.cars.com

 

2).  I have an internal file path like this:  cars/transport/sport/bmw/model.html  and cars is the root folder where apache points to.

 

3).  I assigned my file path to a variable I called $destination

 

4).  I then used this php to redirect to my page.

<commerical cms code that generates some menus>
  <?php
  $destinationUrl="/..$destinationUrl";
  ?>
</commerical cms code that generates some menus>

<!-- redirect clicked menu above to access web content -->
<?php
<!-- strips  "cars/" from the  path "cars/transport/sport/bmw/model.html"  -->
$destinationUrl=substr($destinationUrl, 5);


<!-- SHOULD redirect to or embeds "transport/sport/bmw/model.html"  to "www.cars.com/ -->
header("Location: ..$destinationUrl");
exit;
?>

 

5).  But my result is Not Found: www.cars.com/cars/transport/sport/bmw/model.html

 

    instead of  www.cars.com/transport/sport/bmw/model.html

 

6).  How do i solve this.  Thank you.

 

 

 

 

 

a.) What is the purpose of this...

 

$destinationUrl="/..$destinationUrl";

 

b.) If you have a folder called cars in your root directory that contains a folder called transport and so on, what makes you think http://www.yourdomain.com/transport/ will work? Unless you also have a folder called transport in your root directory that will not work. If you wish that URL to point to http://www.yourdomain.com/cars/transport then you would need to use an .htaccess file (or alternative) to forward the URL.

$destinationUrl = "../" . $destinationUrl; #Up one level, substr not neccessary...

 

You are also using HTML comments (<!-- COMMENT -->) in PHP tags.

you should be using


// Single line comment
#  Single line comment
/*
   Multi
   Line
   Comment
*/

 

header("Location: " . $destinationUrl);

 

a.) What is the purpose of this...

 

$destinationUrl="/..$destinationUrl";

 

b.) If you have a folder called cars in your root directory that contains a folder called transport and so on, what makes you think http://www.yourdomain.com/transport/ will work? Unless you also have a folder called transport in your root directory that will not work. If you wish that URL to point to http://www.yourdomain.com/cars/transport then you would need to use an .htaccess file (or alternative) to forward the URL.

 

Thank you for your response, to clarify:

 

a). 

$destinationUrl="/..$destinationUrl";

  this code processes menus as I have stated and also extracts the current path of the file.html.  if u noticed I have enclosed that php with some tags that represent the cms i have. 

 

b). I stated that the folder car is the folder that is pointed to by apache.  so in other words my www.cars.com is the url for the word car.  in other words my www is car.  its hard to believe but the cms i have makes it possible.  By the way I am using my own web server.

Thank you for your response, to clarify:

 

a). 

$destinationUrl="/..$destinationUrl";

  this code processes menus as I have stated and also extracts the current path of the file.html.  if u noticed I have enclosed that php with some tags that represent the cms i have. 

 

In HTML links a preceeding forward slash means 'root directory'. A double dot means parent directory. Which means you'd be asking for the parent of the root something which to my knowledge would simply result in the link being relative to root (which it was in the first place as far as I can tell). Aside from that, the line would only work if $desitnationUrl had a preceeding forward slash. It appears your's doesn't which would make the link /..cars/transport/sport/bmw/model.html.

 

Of course this is purely theoretical because I'm not sure of the value of $destinationUrl at the start of your script.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.