tags:

views:

95

answers:

3

Hello,

My question and the thing that goes wrong

is when I have two segments

example: www.xxx.nl/products/id

and I have this in the htaccess

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]

is there a solution, or is this caust by the host

thanks in advance , Richard

A: 

The requested URI path and query is in $_SERVER['REQUEST_URI']. You can get the segments with this:

$_SERVER['REQUEST_URI_PATH'] = preg_replace('/\?.*/', '', $_SERVER['REQUEST_URI']);
$segments = explode('/', ltrim('/', $_SERVER['REQUEST_URI_PATH']));
Gumbo
but why not in the get variable url, just for clarification
Richard
You don’t need to pass the requested URL in a parameter when it’s already there.
Gumbo
no, that's not what I want.I need the logical adresses.
Richard
@Gumbo, it seemed I was to quick. I can process the segments.Only the page does not display normal anymore. But I don't need the page.I only need to send xml back. Sorry
Richard
still, it should put the segments in the get variable and display the page normally I would think?
Richard
+2  A: 

You can use the parse_url function to parse any url and seperate it into relevant parts (assuming it's a valid url).

tj111
thanks, I needed it for a webservice.I still can't get my head around it completely
Richard
A: 

The url passed to index.php will never include the hostname, port, or query string. (Source: mod_rewrite docs).

Since the rest of the url is separated by forward slashes, you could use explode to turn it into an array.

$uri_segments = explode('/', $_GET['url']);

Note: What the array actually contains depends on where the RewriteRule occurs. If it's in an .htaccess file or <Directory> block, parts of the matched block will be missing (anything before the current directory in the url).

R. Bemrose
thanks, I have itfor using REST I can now use a class for the first segment, the second for the method, the third for any more variables.The problem above was related to a css file that did not started with a slash. Now I can go figuring the rest out.
Richard