5

I have been spending hours on this issue and hope to find my way out. I have set up laravel correctly, created a project myapp

My route.php file just contains

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

Route::get('/users', function()
{
    return 'Users!';
});

When I run

http://localhost/myapp/public/

I get the laravel start page correctly

When I run

http://localhost/myapp/public/users

I get

The requested URL /myapp/index.php was not found on this server.

I don't know why its looking for index.php.

When I run

http://localhost/myapp/public/index.php/users

I get a page with text "Users". I should obtain this page when running

http://localhost/myapp/public/users

instead.

Below is my .htaccess

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>

    RewriteEngine On
    Rewritebase /myapp/
    # Redirect Trailing Slashes...
    RewriteRule ^(.*)/$ /$1 [L,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>

Any ideas? Am running a Apache on Linux.

Kevin Joymungol
  • 1,764
  • 4
  • 20
  • 30

7 Answers7

5

Your RewriteBase is set to /myapp/ but your index.php file is in /mayapp/public/ is it not?

As such, I think you'll find the RewriteBase needs to be /myapp/public/.

alexrussell
  • 13,856
  • 5
  • 38
  • 49
  • Thanks! In my case, my Laravel app was one level further down in my folder structure, but by judiciously modifying the `index.php` entry file, as well as adding a `RewriteBase` to the `.htaccess` worked wonders. – Phil Ryan Jun 19 '19 at 00:18
2
  1. Make sure you have mod_rewrite enabled on apache web server.
  2. Make sure that your vhost config allows and parses htaccess files
Valdas
  • 1,074
  • 13
  • 20
1

Just do this and try to restart the apache.

sudo a2enmod rewrite

To restart apache: sudo services apache2 restart

Elshan
  • 7,339
  • 4
  • 71
  • 106
1

I ran into same problem with production server, nothing seemed to work, no chmod/s no other solution but adding a simple line to .htaccess worked.

RewriteBase /

Thanks to the thread and user odaria

0

In your application/config/application.php file change:

'index' => 'index.php',

to:

'index' => '',

That should tell laravel not to use index.php and to rewrite correctly.

It works with standard .htaccess file which comes with laravel (haven't checked if you modified it)

Tom
  • 3,654
  • 2
  • 16
  • 23
0

Use this re-write rule:

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

Also, in `application/config/app.php' change:

'index' => 'index.php'

to

'index' => ''

ajtrichards
  • 29,723
  • 13
  • 94
  • 101
  • Just a small modification in your answer. RewriteBase should be /myapp, no underscore. There was no index,php entry in my app.php, I just added the line. Now even root path not working getting URL /myapp/index.php was not found on this server. Reverted my .htaccess and root path works. Any other suggestions? – Kevin Joymungol Feb 24 '14 at 09:56
0

The quickest way is to add a symbolic link in command line:

ln -s your/acutal/path/myapp/public app-dev

Now browse http://localhost/app-dev should work fine as well as all the routes. You can change app-dev to whatever you want as the name.

JustinHo
  • 4,695
  • 3
  • 20
  • 20