Reputation: 14740
I’m having some issues getting my Laravel project up and running on a shared hosting account. Of course, this works fine locally and it was working fine on the hosting account a couple days ago; I'm not sure what I could have changed to make it stop working.
Being that it’s a shared host, I don’t think I have the ability to change httpd.conf
, but I can of course modify .htaccess
.
I wanted a place to store multilple apps, so my plan was to create a new folder in my web root for each Laravel project. This is how I currently have it set up (not sure if this is a good way to do it or not):
Then map the public folder of each of these folders to a subdomain:
Here’s the problem: when I try to hit any route besides the root page '/'
, I get a 404
error. This is the generic 404 from the host, not from Laravel. When I try to access via the subdomain, I get a 500
error.
If I visit:
404 error
500 error
(error happens immediately)I’ve seen other questions that mention changing settings in httpd.conf
, but I don’t believe I have access to do that. Given that this was previously working for me, I think there is a solution outside of that.
What can I do to prevent these errors?
Also, why would I get different errors when hitting the page from http://example.com/App1/public vs http://app1.example.com ?
Any help would be greatly appreciated..!
Not sure if this will help, but here’s my .htaccess code (Laravel 5.4.21 default):
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>
Upvotes: 0
Views: 1830
Reputation: 14740
This issue was resolved by modifying the Laravel default .htaccess
file by adding the line:
RewriteBase /
This fixed both the 404
and 500
errors.
So altogether:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
RewriteBase /
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>
Upvotes: 2