Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel htaccess

I've setup a new install of Laravel on my local. It appears there are issues with htaccess or Apache settings. I've researched for a number of hours and tried everything I read.

  • OSX Lion 10.7.5
  • MAMP 3.0.5
  • PHP 5.5.10
  • mod_rewrite is being loaded.

My development server works with other sites. This is the first time I am trying Laravel 4.

I get a 403 Forbidden on the welcome page which is located at website.dev:8888/

Apache gives me this error: Directory index forbidden by Options directive

Here is my .htaccess file content:

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

    RewriteEngine On

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

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

Here are a few additional actions I've taken:

  • AllowOverride is set to All in httpd.conf
  • Added virtual host code section to httpd-vhosts.conf
  • verified that the hosts file contains a line for the site 127.0.0.1 website.dev

I've also tried various lines in the htaccess which I found in articles and I also restarted apache each time I made changes to the conf files. No routes work. When I go to website.dev:8888/public I get a blank page, no error. If I go to a route I created such as website.dev:8888/users I get a 404 not found error.

Thank you for your help!

like image 329
Alexnl Avatar asked Jul 07 '14 21:07

Alexnl


People also ask

Does Laravel use htaccess?

The framework ships with a public/. htaccess file that is used to allow URLs without index. php . If you use Apache to serve your Laravel application, be sure to enable the mod_rewrite module.

Where is htaccess in Laravel?

htaccess file for redirecting to Laravel's public folder. In Laravel the path for serving your web page is in the /public folder. By default after installing Laravel and navigating in a browser to the URL you will see a directory listing of all the Laravel files.

How do I create a .htaccess file in Laravel?

htaccess file to redirect requests to the Laravel /public folder user mod_rewrite. Create a . htaccess file in your root directory and add the following code. Save your file and refresh your browser, you should now see the default Laravel splash page.

What is .htaccess file and why it is used?

. htaccess files (or "distributed configuration files") provide a way to make configuration changes on a per-directory basis. A file, containing one or more configuration directives, is placed in a particular document directory, and the directives apply to that directory, and all subdirectories thereof.


2 Answers

This solution worked fine, best solution ever for me. Paste this code into root htaccess. That's all. Leave all other files as they are

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

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ ^$1 [N]

RewriteCond %{REQUEST_URI} (\.\w+$) [NC]
RewriteRule ^(.*)$ public/$1

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ server.php
</IfModule>
like image 135
Mohammad H. Avatar answered Sep 19 '22 10:09

Mohammad H.


In the root path create a .htaccess file with

<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On

RewriteCond %{REQUEST_URI} !^/public/ 

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f



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

In public directory create a .htaccess file

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

    RewriteEngine On

    # Handle Authorization Header
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} (.+)/$
    RewriteRule ^ %1 [L,R=301]

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

if you have done any changes in public/index.php file correct them with the right path then your site will be live.

what will solve with this?

  • Hosting issue of laravel project.
  • Css not work on laravel.
  • Laravel site not work.
  • laravel site load with domain/public/index.php
  • laravel project does not redirect correctly
like image 22
Rutvik Panchal Avatar answered Sep 22 '22 10:09

Rutvik Panchal