Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Uri Class problem
  • Hi, I tried to google what I need, but I can't find it. Here is my question :
    When I use Uri::current(), is there a way of taking off the public in the url?
    I saw that you can extend the class and modify the segment, but isn't it something easier I can do to achieve that?

    Example : I would like to have
    www.localhost.com/blog/posts,
    but instead it return :
    www.localhost.com/public/blog/posts.

    Your help would really be appreciated because I really dont want to find a cheap workaround!
    Thanks!
  • ilNotturnoilNotturno
    Accepted Answer
    Hi, I hade the same problem and I've found this solution:

    1) Move the "index.php" file from public folder to the main folder, so it will be in the "/project" folder and not in "project/public/" folder

    2) In the same "/project" folder create a file called ".htaccess" and put in this code:

    [code]
    <IfModule mod_rewrite.c>
        RewriteEngine on
       
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d

        RewriteRule ^(.*)$ index.php/$1 [L]
    </IfModule>
    [/code]

    Now it should work! Let me know if you have any problem :)
  • HarroHarro
    Accepted Answer
    If you install FuelPHP inside the document root, instead of having the docroot point to the public folder, you have to make some changes.

    There are several solutions, documented here: http://fuelphp.com/docs/installation/instructions.html#/install_inside_root
  • Thank you for your answers, but I heard that there were security issues when installing it in the docroot? Would extending the URI class and trying to take off the public segment be a good idea?
  • I read the part when it's shown how to install in the docroot, but it is the security issue is mentionned there as well.
  • HarroHarro
    Accepted Answer
    In the standard build all code is outside the docroot. Not really to introduce security (almost all files are classes, and not executable code), but something that can't be accessed, can't be hacked or misused. So it's more of a precaution.

    I am not saying you should install it in the docroot (you shouldn't if that is possible), I'm just responding to the fact that you did, and now have an issue.

    In the standard setup, with your webservers docroot pointing to /public, this issue does not exist, because as far as the webserver is concerned, there is no "public". It doesn't see it. Is sees only /index.php.

    You only have this issue if you install the entire FuelPHP installation in your webservers docroot, because then all of a sudden the frameworks access point becomes /public/index.php. For which several solutions exist that do not involve changing any code.
  • Ok I understand, but now the folder structure is the same, the public folder is still there. I'm not sure I understand how to get the good url with URI::current(). Thanks for the explanation on public folder, but my main problem is the URI class that is not sending url I want.

    Thanks!
  • HarroHarro
    Accepted Answer
    The URI class creates the current URI based on your installation.

    In a standard FuelPHP setup you have the following structure:
    /fuel
    /fuel/app
    /fuel/core
    /public

    And in your webserver configuration, you should have a DocumentRoot that should point to /public of that installation. If your DocumentRoot points to / (i.e. the root folder in which you have installed everything), you have a non-standard setup.

    And with a non-standard setup, you either remove /public by moving it's contents one folder level up (because that contents should be in the docroot), or you use rewrite rules to get rid of /public.

    Both solutions work, and do not require any code changes.

    This is exactly what ilNotturno already tried to explain to you.
  • Ok I just understood the whole thing! It works now! My webserver was pointing at / ... I changed it and everything is working! 

    Thanks a lot for your help, I hope this thread will help other.
  • HarroHarro
    Accepted Answer
    No problem, happy coding!

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion