$_SERVER['REQUEST_URI'] and mod_rewrite

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ynwa
Forum Newbie
Posts: 5
Joined: Wed Jan 23, 2008 8:42 am

$_SERVER['REQUEST_URI'] and mod_rewrite

Post by ynwa »

Hi
I have an .htaccess file

Code: Select all

RewriteEngine on 
 
Options +FollowSymlinks
 
RewriteBase /
 
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
 
RewriteRule ^(.*)$ /index.php [L,QSA]
when I'm trying to get pahe http://cms/guestbook/index/

I have such result

Code: Select all

$url = explode ('/', $_SERVER['REQUEST_URI']);
echo '<pre>';
print_r($url);
echo '</pre>';

Code: Select all

Array
(
    [0] => 
    [1] => guestbook
    [2] => index
    [3] => 
)
Why do I have this empty elements, i think that is because folders? What I have to do to delete this elements?
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: $_SERVER['REQUEST_URI'] and mod_rewrite

Post by Christopher »

The string has slashes at the beginning and end.
(#10850)
ynwa
Forum Newbie
Posts: 5
Joined: Wed Jan 23, 2008 8:42 am

Re: $_SERVER['REQUEST_URI'] and mod_rewrite

Post by ynwa »

And how can I delete this slashes, maybe I have wrong rule at mode rewrite? In future I want to use frontController, and I have to parse $_SERVER['REQUEST_URI'] and I think that first element is action and second - controller, but this empty elements, I don't like it :\
User avatar
Zoxive
Forum Regular
Posts: 974
Joined: Fri Apr 01, 2005 4:37 pm
Location: Bay City, Michigan

Re: $_SERVER['REQUEST_URI'] and mod_rewrite

Post by Zoxive »

Code: Select all

$NoBeginningOrEndingSlashes = trim($Var.'/');
Post Reply