Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Problem with URL rewrite
  • Hi, I'm new to Fuel and after installing I got a problem calling controllers. localhost/fuel/public works fine, also routing to another controller via configure.php. But calling any other url like localhost/fuel/welcome or localhost/fuel/public/welcome doesn't work... I'm using Ubuntu 10.10, Apache 2.2.16 and PHP 5.3.3 and mod_rewrite enabled Any idea?? Jannik
  • Harro Verton wrote on Tuesday 12th of July 2011:
    Maybe a rights issue? Or a rewrite issue?
    Apparently it was a rewrite issue.
    Today I play around with my .htaccess file and managed to bring back the documentation (docs) URL alive. Before, I copy and paste the code from your previous post (http://www.fuelphp.com/forums/posts/view_reply/1017) and my .htaccess was:
    <IfModule mod_rewrite.c>
        RewriteEngine on
        RewriteBase /fuel/public
        RewriteCond %&#123;REQUEST_FILENAME} !-f
        RewriteCond %&#123;REQUEST_FILENAME} !-d
    
        RewriteRule ^(/)?$ index.php/$1 [L]         <-- PAY ATTENTION TO THIS LINE
    
        RewriteRule ^(.*)$ index.php/$1 [L]
    </IfModule>
    
    And then I re-read the FuelPHP online documentation, and noticed the structure. So I changed it to:
    <IfModule mod_rewrite.c>
        RewriteEngine on
        RewriteBase /fuel/public
    
        RewriteRule ^(/)?$ index.php/$1 [L]         <-- AND MOVED IT HERE
    
        RewriteCond %&#123;REQUEST_FILENAME} !-f
        RewriteCond %&#123;REQUEST_FILENAME} !-d
        RewriteRule ^(.*)$ index.php/$1 [L]
    </IfModule>
    
    And my local documentation is back!
    :D
  • Just for my curiosity: what do you think that line does?
  • Have you got your htaccess base_url set to "/fuel/public/"?
    Because that could be a problem?
  • Jannik Zappe wrote on 01/30/11 12:13 pm:
    Hi,
    ... I'm using Ubuntu 10.10, Apache 2.2.16 and PHP 5.3.3 and mod_rewrite enabled Any idea?? Jannik

    Hi Jannil, I don't know if you have found the solution for this problem since the post is couple months old. I had the same problem and I solved the problem from this thread post #13. How to enable mod_rewrite in Ubuntu server?? I just double checked to make sure my mod_rewrite is enabled. And then change all AllowOverride None to AllowOverride All. Please make sure to make each word upper case or Apache2 may not be happy. Even this is a late reply, but hopefully this helps.
  • Harro Verton wrote on Thursday 14th of April 2011:
    You are not supposed to put all code inside your webservers docroot. The 'public' folder should be your docroot, all other folders should be outside the docroot for security reasons. If you insist on setting it up like this (which is ok for local dev purposes I guess), you need an .htaccess in the docroot that contains
    <IfModule mod_rewrite.c>
        RewriteEngine on
    
        RewriteBase /public
    
        RewriteCond %&#123;REQUEST_FILENAME} !-f
        RewriteCond %&#123;REQUEST_FILENAME} !-d
    
        RewriteRule ^(.*)$ index.php/$1 [L]
    
        # make sure to capture root requests too
        RewriteRule ^(/)?$ index.php/$1 [L]
    </IfModule>
    

    I have updated the installation documentation to include this instruction.

    Hi, I installed Fuel 1.0-rc3 using EasyPHP on my Windows 7.
    My dir structure is:
    www
         |-- fuel
                 |-- docs
                 |-- fuel
                 |-- public
    
    I add a .htaccess on fuel root using the above setting, but when I go to http://127.0.0.1:888/fuel, the browser returns Object not found! ERROR 404. But when I go to http://127.0.0.1:888/fuel/public, I got a successful Fuel installation message. Any ideas where I go wrong?
  • Ah, I tried to change RewriteBase /public to RewriteBase /fuel/public on my .htaccess in the fuel installation root just like what FrenkyNet suggested:
    <IfModule mod_rewrite.c>
        RewriteEngine on
    
        RewriteBase /fuel/public
    
        RewriteCond %&#123;REQUEST_FILENAME} !-f
        RewriteCond %&#123;REQUEST_FILENAME} !-d
        RewriteRule ^(/)?$ index.php/$1 [L]
        RewriteRule ^(.*)$ index.php/$1 [L]
    </IfModule>
    
    and it works! Silly me. Thanks FrenkyNet for pointing this out. Sorry I missed your post.
    Thank you.
    :D
  • Oh my.
    After successfully displaying the welcome page, I ran into another problem.
    Now the documentation is acting weird.
    The only documentation section I can access were pages in these URLs:
    [url=http://127.0.0.1:8888/fuel/docs/installation/instructions.html]http://127.0.0.1:8888/fuel/docs/installation/instructions.html[/url]
    [url=http://127.0.0.1:8888/fuel/docs/installation/download.html]http://127.0.0.1:8888/fuel/docs/installation/download.html[/url]
    [url=http://127.0.0.1:8888/fuel/docs/installation/troubleshooting.html]http://127.0.0.1:8888/fuel/docs/installation/troubleshooting.html[/url]
    
    the other sections/URL returns:
    Uh Oh!
    Nope, not here.
    Bloody Hell!
    etc.
    What's quite strange is I can access http://127.0.0.1:8888/fuel/docs/ but not http://127.0.0.1:8888/fuel/docs/index.html Any ideas?
    :(
  • Although it looks like an abandoned topic I am having the same problem here. I have a development server (using Zend Server 5.1.0) and I have already checked the httpd.conf file more than once. The module mod_rewrite is loading correctly and I have changed all the Directory's AllowOverride directives to All. I have tried both .htaccess with and without the RewriteBase *url* directive without luck. My FUEL installation is as follows: htdocs (Web Document Root)
    |- fuel_station
    |- fuel
    |-public
    |-index.php My .htaccess file is this:
    <IfModule mod_rewrite.c>
        RewriteEngine on
    
        RewriteCond %&#123;REQUEST_FILENAME} !-f
        RewriteCond %&#123;REQUEST_FILENAME} !-d
     
        RewriteRule ^(.*)$ index.php/$1 [L]
    </IfModule>
    

    I enabled the RewriteLog with Level 9 to see what was going on. I got this when I tried with 'http://localhost/fuel_station/public/welcome':
    127.0.0.1 - - [13/Apr/2011:17:14:43 --0500] [localhost/sid#5e5150][rid#1118910/initial] (3) [perdir D:/Web Development/htdocs/fuel_station/public/] strip per-dir prefix: D:/Web Development/htdocs/fuel_station/public/welcome -> welcome
    127.0.0.1 - - [13/Apr/2011:17:14:43 --0500] [localhost/sid#5e5150][rid#1118910/initial] (3) [perdir D:/Web Development/htdocs/fuel_station/public/] applying pattern '^(.*)$' to uri 'welcome'
    127.0.0.1 - - [13/Apr/2011:17:14:43 --0500] [localhost/sid#5e5150][rid#1118910/initial] (4) [perdir D:/Web Development/htdocs/fuel_station/public/] RewriteCond: input='D:/Web Development/htdocs/fuel_station/public/welcome' pattern='!-f' => matched
    127.0.0.1 - - [13/Apr/2011:17:14:43 --0500] [localhost/sid#5e5150][rid#1118910/initial] (4) [perdir D:/Web Development/htdocs/fuel_station/public/] RewriteCond: input='D:/Web Development/htdocs/fuel_station/public/welcome' pattern='!-d' => matched
    127.0.0.1 - - [13/Apr/2011:17:14:43 --0500] [localhost/sid#5e5150][rid#1118910/initial] (2) [perdir D:/Web Development/htdocs/fuel_station/public/] rewrite 'welcome' -> 'index.php/welcome'
    127.0.0.1 - - [13/Apr/2011:17:14:43 --0500] [localhost/sid#5e5150][rid#1118910/initial] (3) [perdir D:/Web Development/htdocs/fuel_station/public/] add per-dir prefix: index.php/welcome -> D:/Web Development/htdocs/fuel_station/public/index.php/welcome
    127.0.0.1 - - [13/Apr/2011:17:14:43 --0500] [localhost/sid#5e5150][rid#1118910/initial] (2) [perdir D:/Web Development/htdocs/fuel_station/public/] strip document_root prefix: D:/Web Development/htdocs/fuel_station/public/index.php/welcome -> /fuel_station/public/index.php/welcome
    127.0.0.1 - - [13/Apr/2011:17:14:43 --0500] [localhost/sid#5e5150][rid#1118910/initial] (1) [perdir D:/Web Development/htdocs/fuel_station/public/] internal redirect with /fuel_station/public/index.php/welcome [INTERNAL REDIRECT]
    127.0.0.1 - - [13/Apr/2011:17:14:43 --0500] [localhost/sid#5e5150][rid#115cf80/initial/redir#1] (3) [perdir D:/Web Development/htdocs/fuel_station/public/] add path info postfix: D:/Web Development/htdocs/fuel_station/public/index.php -> D:/Web Development/htdocs/fuel_station/public/index.php/welcome
    127.0.0.1 - - [13/Apr/2011:17:14:43 --0500] [localhost/sid#5e5150][rid#115cf80/initial/redir#1] (3) [perdir D:/Web Development/htdocs/fuel_station/public/] strip per-dir prefix: D:/Web Development/htdocs/fuel_station/public/index.php/welcome -> index.php/welcome
    127.0.0.1 - - [13/Apr/2011:17:14:43 --0500] [localhost/sid#5e5150][rid#115cf80/initial/redir#1] (3) [perdir D:/Web Development/htdocs/fuel_station/public/] applying pattern '^(.*)$' to uri 'index.php/welcome'
    127.0.0.1 - - [13/Apr/2011:17:14:43 --0500] [localhost/sid#5e5150][rid#115cf80/initial/redir#1] (4) [perdir D:/Web Development/htdocs/fuel_station/public/] RewriteCond: input='D:/Web Development/htdocs/fuel_station/public/index.php' pattern='!-f' => not-matched
    127.0.0.1 - - [13/Apr/2011:17:14:43 --0500] [localhost/sid#5e5150][rid#115cf80/initial/redir#1] (1) [perdir D:/Web Development/htdocs/fuel_station/public/] pass through D:/Web Development/htdocs/fuel_station/public/index.php
    
    I got an error using this url, nothing was shown although it should have displayed the default welcome view for FUEL.
    I then tried another url, without the controllers name, and I got this (using: 'http://localhost/fuel_station/public'):
    127.0.0.1 - - [13/Apr/2011:17:15:28 --0500] [localhost/sid#5e5150][rid#1116908/initial] (3) [perdir D:/Web Development/htdocs/fuel_station/public/] strip per-dir prefix: D:/Web Development/htdocs/fuel_station/public/ -> 
    127.0.0.1 - - [13/Apr/2011:17:15:28 --0500] [localhost/sid#5e5150][rid#1116908/initial] (3) [perdir D:/Web Development/htdocs/fuel_station/public/] applying pattern '^(.*)$' to uri ''
    127.0.0.1 - - [13/Apr/2011:17:15:28 --0500] [localhost/sid#5e5150][rid#1116908/initial] (4) [perdir D:/Web Development/htdocs/fuel_station/public/] RewriteCond: input='D:/Web Development/htdocs/fuel_station/public/' pattern='!-f' => matched
    127.0.0.1 - - [13/Apr/2011:17:15:28 --0500] [localhost/sid#5e5150][rid#1116908/initial] (4) [perdir D:/Web Development/htdocs/fuel_station/public/] RewriteCond: input='D:/Web Development/htdocs/fuel_station/public/' pattern='!-d' => not-matched
    127.0.0.1 - - [13/Apr/2011:17:15:28 --0500] [localhost/sid#5e5150][rid#1116908/initial] (1) [perdir D:/Web Development/htdocs/fuel_station/public/] pass through D:/Web Development/htdocs/fuel_station/public/
    127.0.0.1 - - [13/Apr/2011:17:15:28 --0500] [localhost/sid#5e5150][rid#11108f0/subreq] (3) [perdir D:/Web Development/htdocs/fuel_station/public/] strip per-dir prefix: D:/Web Development/htdocs/fuel_station/public/index.php -> index.php
    127.0.0.1 - - [13/Apr/2011:17:15:28 --0500] [localhost/sid#5e5150][rid#11108f0/subreq] (3) [perdir D:/Web Development/htdocs/fuel_station/public/] applying pattern '^(.*)$' to uri 'index.php'
    127.0.0.1 - - [13/Apr/2011:17:15:28 --0500] [localhost/sid#5e5150][rid#11108f0/subreq] (4) [perdir D:/Web Development/htdocs/fuel_station/public/] RewriteCond: input='D:/Web Development/htdocs/fuel_station/public/index.php' pattern='!-f' => not-matched
    127.0.0.1 - - [13/Apr/2011:17:15:28 --0500] [localhost/sid#5e5150][rid#11108f0/subreq] (1) [perdir D:/Web Development/htdocs/fuel_station/public/] pass through D:/Web Development/htdocs/fuel_station/public/index.php
    
    This time the default welcome view was correctly shown. Both times the mod_rewrite made the final pass through the same path (D:/Web Development/htdocs/fuel_station/public/index.php) so I don't understand why it's not working properly. This Framework has lots to offer from what I've read since it addresses many things that other Frameworks lack of or are restricted to... so I would like to be able to test it... Anyone's help would be very much appreciated...
  • Maybe a rights issue? Or a rewrite issue?
  • Ok, this is odd but points me to the right direction: I just tested FUEL in an xampp platform and worked like a charm right away! (Before I was working with a Zend Server installation...) If anyone knows why FUEL does not get along with the Zend Server platform please share! I'll try to figure it out...
  • You are not supposed to put all code inside your webservers docroot. The 'public' folder should be your docroot, all other folders should be outside the docroot for security reasons. If you insist on setting it up like this (which is ok for local dev purposes I guess), you need an .htaccess in the docroot that contains
    <IfModule mod_rewrite.c>
        RewriteEngine on
    
        RewriteBase /public
    
        RewriteCond %&#123;REQUEST_FILENAME} !-f
        RewriteCond %&#123;REQUEST_FILENAME} !-d
    
        RewriteRule ^(.*)$ index.php/$1 [L]
    
        # make sure to capture root requests too
        RewriteRule ^(/)?$ index.php/$1 [L]
    </IfModule>
    

    I have updated the installation documentation to include this instruction.
  • Thanks for your reply WanWizard, I know... at the time it just was easier as I didn't have to rearrange folders (lazy I know) and yes it was for dev pourposes, mainly for getting to know fuel... Well, I did few things last night. I reinstalled my Windows and made a clean install of the Zend Server. I put the fuel distribution as recomended and try to run the framework. Same errors... When I enter [url=http://localhost]http://localhost[/url] as the address it works and displays the welcome screen. But as soon as I enter [url=http://localhost]http://localhost[/url]/welcome it gives me an error that it could not find the address... I did of course change the httpd.conf file to set the AllowOverride directive to All. Also the the .htaccess file is now in the docroot folder (the default .htaccess, without your modifications).It still doesn't work. I've not enabled the RewriteLog this time, so I'll run some tests to see if at this point it's a rewrite problem or something else... I installed xampp 1.7.4 and did the same test and it runs flawlessly... so it is something with Zend Server config. I disabled everything (Zend Optimizer and all Zend additional components with no luck at all). Someone knows what's happening? In the meantime I can test fuel with xampp :D
  • Don´t forget to set `AllowOverride` to `All` in your Virtual host file "/etc/apache2/sites-available/default" that was my problem.
  • To be complete:

    "All" isn't really needed, the minumum you need is "FileInfo".

    With "All" you also enable auth overrides and directory indices, which might have security side-effects...

    The current release has a fully operational .htaccess in the public folder, that works for a variety of setups. In the (1.7+) docs there are examples on how to deal with rewrites when installing inside the docroot.

Howdy, Stranger!

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

In this Discussion