Laravel 4 routing not working due to .htaccess file?

I write my steps and results here so you can see what I have tried and what results I have. Any advice would be appreciated. I followed the comments in this answer .

I am running Laravel 4 using XAMMP version 1.8.2 with PHP 5.4.19 and Apache 2.4.4 on a Windows 7 machine, and I'm just still trying to start a local instance.

In my case: http://localhost/sos/sos_public/ is my main screen, and it works, but when I try to get to http://localhost/sos/sos_public/signup , I get this error: Symfony \ Component \ HttpKernel \ Exception \ NotFoundHttpException , which was talked about a lot on the network, and then I found GaryJ , indicating that this could be a .htaccess problem, so I did what he suggested.

My /app/routes.php file looks like this (I tried this with / before signup too):

 Route::get('signup', function() { return 'hello!'; }); Route::get('/', function() { return View::make('hello'); }); 

Firstly:

Just for fun, see if /index.php/hello works. If so, then this is a .htaccess problem.

http://localhost/sos/sos_public/index.php/signup worked fine. So this is the .htaccess problem.

My .htaccess file looked like this:

 <IfModule mod_rewrite.c> Options -MultiViews RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^ index.php [L] </IfModule> 

AND

if you are using Apache 2.4 , pay attention to the changes since the previous version regarding Require all granted and AllowOverride all within <Directory />...</Directory> on your virtual host.

I added this to my httpd.conf file , as suggested by Dalton Gore - I got the Symfony \ Component \ HttpKernel \ Exception \ NotFoundHttpException (changed this directory path to /SOS/sos_public and C:/xammp/htdocs/SOS/sos_public/ and C:/xammp/htdocs/SOS/sos_public - same results):

 <Directory /> AllowOverride none Require all denied </Directory> <Directory /SOS/sos_public> AllowOverride all Require all granted </Directory> 

Further:

Check if anything works in .htaccess

I added dsjkdsfghk to my .htaccess file and immediately got an error, so I know that my .htaccess file .htaccess used.

Then:

Try removing the IfModule condition. Since you have access to host / vhost, you can enable this module in the near future, if this is not so, then you do not need to check it with every request. Equally, try moving it from .htaccess and to the <Directory />...</Directory> block in your vhost - if you have nothing else in your .htaccess, then this can also be deleted.

  • Having an empty .htaccess file caused a 404 error in my browser for http://localhost/sos/sos_public/signup ( http://localhost/sos/sos_public/ still worked).
  • Removing the .htaccess file from C:\xampp\htdocs\SOS\sos_public\ had the same results.

Then:

Try: <VirtualHost *:80> DocumentRoot "/Users/amiterandole/Sites/laravelbackbone/public" ServerName laravelbackbone.dev <Directory /> AllowOverride all Require all granted </Directory> <IfModule mod_rewrite.c> Options -MultiViews RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^ index.php [L] </IfModule> </VirtualHost>

I did it and just like Amit,

I took out my htaccess file and tried the above, and now nothing seems to work.

Except that its laravelbackbone.dev pointed to its root of the Sites folder, I just got Error 400 - Bad request at http://localhost/sos/sos_public/ and http://localhost/sos/sos_public/signup when I launched them in his browser.

My httpd-vhosts.conf looked like this:

 <VirtualHost *:80> DocumentRoot "C:/xammp/htdocs/SOS/sos_public" ServerName sos.dev <Directory /> AllowOverride all Require all granted </Directory> <IfModule mod_rewrite.c> Options -MultiViews RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^ index.php [L] </IfModule> </VirtualHost> 

and in my .hosts file, I obviously had:

 127.0.0.1 sos.dev 

And finally:

Did you definitely get the conf/extra/httpd-vhosts.conf (without commenting) within the main httpd.conf ?

I have it without comment - yes.

Another link that I tried, but to no avail: https://stackoverflow.com/a/site/questions/117064/ ... and http://www.epigroove.com/blog/laravel-routes-not-working-make-sure-htaccess-is -working

What should I change where? What am I missing?

+2
.htaccess laravel laravel-4 vhosts
Sep 17 '13 at 20:31 on
source share
1 answer

Your server_name

 sos.dev 

And apache keep this in mind, you must access your routes using:

 http://sos.dev/ 

AND NOT

 http://localhost/ 
+1
Sep 17 '13 at 21:17
source share



All Articles