Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel default .htaccess file will not work

I finally got everything installed for Laravel, but I am getting an error 500 on my home page!

It looks to be my .htaccess file. If I remove it the page works. If I put it back, another error 500.

<IfModule mod_rewrite.c>
    Options -MultiViews
    RewriteEngine On

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

If I change that second to last line to "RewriteRule ^index.php [L]" (no space before index.php) then the error 500 goes away but the rewrite rule will not work.

My host is 1and1.com.

Can anybody help me?

like image 214
JLZenor Avatar asked Jun 21 '13 06:06

JLZenor


3 Answers

Changed this line:

    RewriteRule ^ index.php [L]

to this:

    RewriteRule ^ /index.php [L]

Now it works. Not only do I not get the 500 error, but the URLs appear to work as intended.

like image 94
JLZenor Avatar answered Nov 06 '22 19:11

JLZenor


It seems to me the 500 internal error is coming because you have not set the virtual host in the apache httpd.conf file.

Put this line in the httpd.conf file

For windows

NameVirtualHost *:80

<VirtualHost *:80>
    ServerName yourlaravel.com
    DocumentRoot "C:/wamp/www/laravel/public"
    <Directory "C:/wamp/www/laravel/public">
    </Directory>
</VirtualHost>

<VirtualHost *:80>
     ServerName localhost
     DocumentRoot "C:/wamp/www"
     <Directory "C:/wamp/www">
     </Directory>
</VirtualHost>

For Linux

NameVirtualHost *:80
<VirtualHost *:80>
    ServerName yourlaravel.com
    DocumentRoot "/var/www/laravel/public"
    <Directory "/var/www/laravel/public">
 </Directory>

<VirtualHost *:80>
   ServerName localhost
   DocumentRoot "/var/www"
   <Directory "/var/www">
   </Directory>
</VirtualHost>

And to run it in your local machine

For window open the C:\Windows\System32\drivers\etc\hosts put this line.

 yourserverip   yourlaravel.com

For linux open the \etc\hosts put this line.

 yourserverip   yourlaravel.com

Your can refer to this link for further info:

http://net.tutsplus.com/tutorials/php/building-web-applications-from-scratch-with-laravel/

I hope this can be some help.

like image 25
saran banerjee Avatar answered Nov 06 '22 19:11

saran banerjee


It work for me on the most of the project where default one won't work

DirectoryIndex index.php

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

    RewriteEngine On

    RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
    RewriteRule ^(.*) - [E=BASE:%1]

    RewriteCond %{ENV:REDIRECT_STATUS} ^$
    RewriteRule ^index\.php(/(.*)|$) %{ENV:BASE}/$2 [R=301,L]

    RewriteCond %{REQUEST_FILENAME} -f
    RewriteRule .? - [L]

    RewriteRule .? %{ENV:BASE}/index.php [L]

</IfModule>
like image 31
Vinod Raut Avatar answered Nov 06 '22 19:11

Vinod Raut