I've spent the whole last two days trying to deploy my Laravel React Vite website on Hostinger
I followed The instructions from Hostinger docs as below:
I uploaded my website.
created new .env and add my configs.
created a database.
added build folder from react vite after running "npm run build" to the public folder.
edit resource/view/welcome.blade.php with the build js and css src as below #vite(['public/build/assets/app.a0a7c860.js', 'public/build/assets/app.69041b03.css']).
I have already .htaccess file in public folder which is
<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]
# Send Requests To Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
it still gives me 403 error Although it works correctly on localhost
I tried to add new .htaccess in the project directory
as below
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
now it gives me 500 server error
I am in doubt that hostinger couldn't recognize my project structure
How to solve that problem?
Related
I have a problem with .htaccess configuration for multiple Laravel projects on my Apache webserver. One project in the root folder and one project in a subfolder
File structure (/www)
/ <-- Laravel application #1
/anotherProject <-- Laravel application #2
When I'm visiting www.example.com/anotherProject then I get a 404 error (and www.example.com is working. The following .htaccess is activate in /public/ (for Laravel application #1).
/public/.htaccess
<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]
# Send Requests To Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
It feels like I need to change something in the .htaccess file of the project in the root folder. Has someone a suggestion to try?
I've a domain, like www.example.com
The main site is on FTP space visible as /example.com
I installed (copy/pasted, sigh... :( ) my Laravel app under /example.com/laravel_app.
I am able to open the laravel app, and it's fully working, if I access using full url http://www.example.com/laravel_app/public/index.php.
The problem is that, obviously, I'd like to access it using only the path http://www.example.com/laravel_app.
In the root of laravel_app, I tried to paste this .htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
While in the /example.com/laravel_app/public i'm using this `.htaccess
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
RewriteBase /laravel_app/
# 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>
So my question is NOT related the .htaccess of app's public folder, but the .htaccess for app's root folder.
How can I succesfully serve
http://www.example.com/laravel_app/public/index.php
accessing
http://www.example.com/laravel_app
?
Actually I got Laravel returning a 404
I tried this variant (seen I some question very similar to this one)
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ public/index.php/$1 [L]
</IfModule>
But with this I got apache returning a forbidden
I'm assuming you have installed your application on shared hosting and ssince it's running Apache this solution should work.
Revert your .htaccess back to its original/what was deployed with laravel.
Ideally you shouldn't have your project uploaded in public_html as it exposes all the files to the web.
Move all your project files except public to a directory below public_html.
Eg.
/home/<username>
[laravel] <-- Make this directory
[public_ftp]
[public_html]
[ssl]
etc..
Then in your public_html move the files inside your public folder to the directory you want to serve your files (address you want to go to to use your app).
/home/<username>/public_html/laravel-app
[public_html]
[laravel-app]
-index.html
-robots.php
-.htaccess
-[css]
-[js]
-[svg]
etc..
Now edit your index.html file in the laravel-app folder and change both:
require __DIR__.'/../vendor/autoload.php';
$app = require_once __DIR__.'/../bootstrap/app.php';
..to reflect the path where you moved yoru project folder.
require __DIR__.'/../../laravel/vendor/autoload.php';
$app = require_once __DIR__.'/../../laravel/bootstrap/app.php';
Essentially in this context ../ means back one folder, so the aim is to take it back to where it will find the laravel/vendor/ folder, vice-versa.
Realistically that should sort your issue out and make for a more secure application as your .env and composer, etc. files will not be publically available without messing with your .htaccess.
Oh, also here is the default .htaccess code which should be under your public folder <project>/public:
<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>
I was given a laravel project I need to get up and running. I am new to laravel, but after allot of work, I believe I got everything configured properly and I deployed the project to heroku.
When I do artisan serve on my guest machine in my laravel project and go to the given url everything works fine all the links works.
But I deploy it to heroku and my index page shows but none of the links work.
I get:
Not Found The requested URL /register was not found on this server.
It seems that running php artisan serve kinda activates the links, but how do I make that happen on heroku???
I should note the app is using blade.php files
What am I missing???
This is in the /resources/views
My _htaccess inside my public folder is as follows
<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>
I tried adding RewriteBase / doesnt help.
I also tried changing htaccess to:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
I'm working with a project in Laravel 5.7. Everything works in localhost. But, after uploading in the server, all routes for Backend Part is working. But post routes for Frontend Part is not working. It shows the error -
403 Forbidden Access to this resource on the server is denied
.htaccess in root folder is -
<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>
Have someone face this problem before? What I've missed. In localhost everything is working fine, but not in Server.
I think you are not generating artisan key. Please run these command on server.
composer update
php artisan key:generate
Your htaccess hould be like this
<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 ^(.*)/$public /$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}]
For handling front end stuffs in /public add this to your .htaccess:
RewriteEngine on
RewriteCond %{REQUEST_URI} !^public
RewriteRule ^(.*)$ public/$1 [L]
.htaccess looks fine to me
Make sure your post routes are being called with form.
If there is no issue in your backend then
You need to grant permissions to server of these directories
give permissions to bootstrap/ and storage/ directory as shown below
sudo chmod -R 777 storage/ bootstrap/
Then it should work
I'm developing a Laravel website. Everything is working fine on localhost. But once hosted online with 1&1, when I add a parameter in the route, it's returning an error 404 (not found).
In 1&1 the root url is redirecting to the file "public" of my laravel project.
And the .htaccess in this public file looks like that :
<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>
Does someone know what could be the problem ?
Try running the following artisan commands on your host:
php artisan optimize
php artisan route:clear
If you don't have access to run these commands, you can call them in code using Artisan::call('optimize') etc.