Jump to content

[SOLVED] url rewrite relating to $_SERVER['REQUEST_URI'] problem


Mr.Shawn

Recommended Posts

$page = explode("/", $_SERVER['REQUEST_URI']);

The above code is to detect uri variables.

 

I always used $page[1] to see what was the first parameters that was parsed in the browser url.

 

Now, the problem is whether you placed your scripts in root directory or in a folder. If I place my scripts and all files in the root directory it would be like this.

 

The debuuged $page values.

Array ( [0] => [1] => ) 

 

If I placed my scripts and all files in one folder then it would be like this

Array ( [0] => [1] => somefolder [2] => ) 

 

I can no longer use $page[1] as the first parameters. Any ideas how I can solve this problem? I want it to be dynamically

Okay this is the case.

 

Normally if I does url rewrite on my software where my software will be located in the root folder, it works all fine. I normally use

$page = explode("/", $_SERVER['REQUEST_URI']);

to return to a variable and then check $page[1]. In this example,

www.example.com/somepages/

where the "somepages" refer to $page[1].

 

But now if I placed my software in a folder, the $page[1] appears to be the folder name and now I have problems retrieving the rewrited url. www.example.com/folder/somepages/

 

How can I solve this problem?

You really should look at the functions parse_url(), pathinfo(), and basename().

 

Example:

<?php
$uri = 'http://www.example.com/folder/somepages/';
$pu = parse_url($uri);
$path = pathinfo($pu['path']);
print_r($pu);
print_r($path);
?>

 

Ken

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.