Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default route fails if index.php is in a subdirectory #78

Open
codazoda opened this issue Feb 14, 2014 · 3 comments
Open

Default route fails if index.php is in a subdirectory #78

codazoda opened this issue Feb 14, 2014 · 3 comments

Comments

@codazoda
Copy link

If I access the index.php that includes Toro.php from a URL with no path it works fine. Here's an example:

mytest.com/

If, however, I access an index.php file that is inside of a directory or two, it fails. Here's an example of that (my index is in /var/www/some/directory/index.php).

mytest.com/some/directory/

What I've found is that the last test in Toro.php that looks at the $_SERVER['REQUEST_URI'] is the problem. That variable returns "/some/directory/" in the case of my script being setup inside a directory. As a result the "/" route fails to work, but the others do work. Here's the failing route code.

Toro::serve(array(
    "/" => "Help",
    "/test" => "Test"
));

If I change the code to the following, it works.

Toro::serve(array(
    "/some/directory/" => "Help",
    "/test" => "Test"
));

By removing the last for $_SERVER['REQUEST_URI']) the problem goes away (because '/' is the default $path_info value).

So, my question is, what does that last $_SERVER['REQUEST_URI'] add that I'm missing here? Should it be removed or put in as an option? If so, I'm happy to make these changes and submit a pull request.

@gyaaniguy
Copy link

Hello. I can confirm this issue as well. removing the last else block (18 line) resolves it, but not sure if it won't cause trouble is some other situation...

@sijad
Copy link

sijad commented Jun 23, 2014

I have this problem too!

@VeeeneX
Copy link

VeeeneX commented Aug 10, 2014

@sijad @kutchbhi You have several options how to fix it I'm using this:
Toro.php

    $uri = @explode('/', $_SERVER['REQUEST_URI'])[2]; //Here you need to find your dir or use GET
    $path_info = ((!empty($uri)) ? $path_info = '/'.$uri : $path_info = '/');

.htaccess

<IfModule mod_rewrite.c>
    RewriteEngine on
    IndexIgnore */*
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*) index.php [L,QSA]
</IfModule>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants