Back

500 Internal Server Error for all routes other than '/'


Hello,

I was receiving a 500 Internal Server Error for all routes other than '/'. After looking at the error log, I saw the following.

Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace.

I had recently changed my local setup to support wildcard dns and wildcard vhosts and I noticed this also happened with an old laravel 3 project as well. This was obviously an vhost or .htaccess issue.

After looking around I found a solution that suggested a change to the RewriteRule. All works fine now. My question is if anyone sees a problem with this rewrite rule, and if not, perhaps it's a good idea to change the standard .htaccess file?

#Laravel 3

# RewriteRule ^(.*)$ index.php/$1 [L]
RewriteRule ^(.+)$ /index.php/$1 [L]

#Laravel 4

#RewriteRule ^ index.php [L]
RewriteRule ^(.+)$ /index.php [L]
rajanrawal replied 4 years ago

Hey Buddy,

Thank you. I had the same issue. Can you please explain why this happened?

visualasparagus replied 4 years ago

I think it's due to the VirtualDocumentRoot that I use and the regex that is used in the rewrite rule for the replacement. But I'm not 100% certain to be honest.

Although now that I look at it, I think the Laravel 4 version should be the below, as otherwise I'm not using the search.

RewriteRule ^(.+)$ /index.php/$1 [L] 

My vhost config is:

NameVirtualHost *:80


<Virtualhost *:80>
    UseCanonicalName Off
    VirtualDocumentRoot "/path/to/general/directory/%-3+/public"
    ServerName vhosts.loc.al
    ServerAlias *.loc.al
	LogFormat "%V %h %l %u %t \"%r\" %s %b" vcommon
    ErrorLog "/path/to/general/directory/log/error_log"
    <Directory "/path/to/general/directory/">
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>
</Virtualhost>

I'm not a regex / vhost guru though, so maybe I'll post an issue on GitHub.

Glad it helped you though.

rajanrawal replied 4 years ago

thank you for your time buddy.

highbelt replied 4 years ago

Thank you! Had the same issue and your solution worked very well for a L4 installation with wildcard subdomain enabled on domainfactory (df.eu).

ezos86 replied 4 years ago

Thank you, thank you, thank you, thank you.

Need I say more?

heroselohim replied 4 years ago

Fixed like magic. Thank you so much !!

pioneer903 replied 4 years ago

This is how my .htaccess looks like.

RewriteEngine On

RewriteCond %{REQUEST_URI} !^/public/.*$

RewriteRule ^(.*)$ /public/$1 [QSA,L] 

It worked fine before on both local and production servers. Now, it doesn't work on the production server. Same as yours, the '/' page is displayed, but the other pages generate 500 error. Using the code rajanrawal suggested produced 403 error on all the pages

oadria replied 4 years ago

I'm not 100% sure if this is the same problem, but I had similar symptoms (local setup worked fine, on a host it gave a 500 internal server error for everything but '/'). I added this line to the .htaccess

RewriteBase /

(after "RewriteEngine On" line) which worked and now both local and host don't show any errors. I read about this solution somewhere, but that was a year ago or so - so I'm not sure where (I just started a new Laravel project and so had the convenience to check an old Laravel project which already works).

nahuelmellusso replied 4 years ago

thanks !

pabloleone replied 3 years ago

Thank you oadria!

You fixed my issue. I push a Laravel 5 instalation to live server and I started getting the 500 error. Adding that line in my .htaccess fixed that.

I think that rule should come by default . What do you think?

Skyrpex replied 3 years ago

Thanks, @oadria!

menatoric59 replied 3 years ago

OMG, thanks @oadria, my issue was fixed. Now, I can do my demos like a Pro !!!

mikevaleriano replied 3 years ago

THANKS! Same thing happening on a Laravel 5 install when using virtual hosts. Simple change, and now routes are working.

kamran7293 replied 3 years ago

visualasparagus said:

Hello,

I was receiving a 500 Internal Server Error for all routes other than '/'. After looking at the error log, I saw the following.

Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace.

I had recently changed my local setup to support wildcard dns and wildcard vhosts and I noticed this also happened with an old laravel 3 project as well. This was obviously an vhost or .htaccess issue.

After looking around I found a solution that suggested a change to the RewriteRule. All works fine now. My question is if anyone sees a problem with this rewrite rule, and if not, perhaps it's a good idea to change the standard .htaccess file?

#Laravel 3

RewriteRule ^(.*)$ index.php/$1 [L]

RewriteRule ^(.+)$ /index.php/$1 [L]

#Laravel 4

#RewriteRule ^ index.php [L] RewriteRule ^(.+)$ /index.php [L]

Thanks, but what is the command for laravel 5?

eddiePower replied 3 years ago

oadria said:

I'm not 100% sure if this is the same problem, but I had similar symptoms (local setup worked fine, on a host it gave a 500 internal server error for everything but '/'). I added this line to the .htaccess

RewriteBase /

(after "RewriteEngine On" line) which worked and now both local and host don't show any errors. I read about this solution somewhere, but that was a year ago or so - so I'm not sure where (I just started a new Laravel project and so had the convenience to check an old Laravel project which already works).

THANK YOU i was searching and searching for a similar issue with the mod rewrite for production routing of any links after the / or home page, changed my .htaccess file in public from RewriteBase /home/me/public_html/blog/public to RewriteBase / and it all works as it did under homestead in development so a big thank you and anyone with a similar sounding issue in Laravel 5 here is a confirmed fix.

iamface replied 3 years ago

@oadria

You've solved this for me as well. RewriteBase / Solved for me.


Sign in to participate in this thread!



We'd like to thank these amazing companies for supporting us