Forum Moderators: coopster
Not sure how to do this but basically I want to be able to extract the unique pagename from a url when the page has been requested. the structure i have is as follows:
www.my-domain-name.com/unique => This is for the initial page/section
www.my-domain-name.com/data1/unique => Where data1 is the parent id and unique is the page within the parent section.
so in the first case, i want to be able to extract unique from the url which is fine, i would use the following:
$page_url_new = "/".addslashes($_GET['unique']);
however if i test this method on a domain such as www.my-domain.com/about_us/project_manager then the unique value returns about_us/project_manager instead of just project_manager.
Not sure i have made this clear or not!
I use Rewrite Mod to do this, more info here on Apache forum [webmasterworld.com].
In .htaccess:
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^(about_us)/?$ index.php?parent=$1 [nc]
RewriteRule ^(about_us)/(project_manager)/?$ index.php?parent=$1&child=$2 [nc]
On index.php you can handle the vars using $_GET['parent'] and $_GET['child'].
[edited by: Psychopsia at 10:45 pm (utc) on Feb. 12, 2007]
I am still not getting the results i am after though.
The examples I gave were only up to 2 levels, however there can be 5/6 levels. Maybe the way I am going about the set-up could be better.
Basically, the files are all content pages - so the .com/welcome would be say pageid=1 and .com/welcome/about would be pageid=2 but a child of pageid=1 and .com/welcome/about/me could be pageid=3 but a child of pageid2.
I thought that the best way would be to strip down the url and only get the last item but have not been able to do so with the examples above.
maybe i am missing a trick here.
you could try these to see what is going on, also look through the $_SERVER [php.net] vars to see what you can use
$myuri = $_SERVER['REQUEST_URI'];
echo '<p>raw URI: ',$myuri;
$uriparts = parse_url [php.net]($myuri);
echo '<p><pre>parse_url:<br>';
print_r($uriparts);
echo '</pre>';
$uriparts2 = explode [php.net]('/',$myuri);
echo '<p><pre>explode<br>';
echo '</pre>';
this will mostly show what data you are getting and give you a better idea what you need to use and then what to do next
Thanks for your response. I had been previously trying to echo results but your notes have bought me 1 step closer to what I am looking for.
$myuri = $_SERVER['REQUEST_URI'];
$uriparts2 = explode('/',$myuri);
My next question is how would i get the last array line, so my current array is:
[0] =>
[1] => dev_site
[2] => meet-the-team
[3] => test
I would need to get unique = [3]. However I would not know how many lines there are as this is created dynamically.
Thanks.
So just
$myuri = $_SERVER['REQUEST_URI'];
$uriparts2 = explode('/',$myuri);
echo end($uriparts2);
Regards
Michal