I'm going crazy here! I'm trying to learn Laravel and pretty URLs just don't work.
I have enabled mod_rewrite
from my apache config file, I have set AllowOverride
to All
in my user config file and I have the following in my .htaccess
file in public
folder of Laravel installation:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php/$1 [L]
I enter http://localhost/~user/lara/public/index.php/users
it works, but with http://localhost/~user/lara/public/users
I get 404 Not Found
error
The requested URL /Users/user/Sites/lara/public/index.php/users was not found on this server.
You can see that the redirection works fine, as public/users
have turned into public/index.php/users
but it says not found, even though when I manually enter public/index.php/users
it show me the output.
I have read all the related questions on SO, none of the worked for me!
This is most likely caused by the fact that you are changing the document root during a request. From the looks of your URL (with the ~user
segment) you are using mod_userdir
or something similar, and what these types of plugins do it allow you to map a given URL prefix to a document root that is not the normal one for the server.
As such, you sometimes run into issues like this where the right .htaccess file is found, but its rewritten URL is against the original document root rather than the modified one and so your index.php
file cannot be found (maybe, to be honest I don't really know, this is all conjecture). This is also why going directly to index.php/users
works - the problem isn't the setup per se, but the mixing of rewrite rules and the change of the document root.
As such, the fix is to use a RewriteBase
line, ad the following to the .htccess file:
RewriteBase /~user/lara/public/