I want to deploy a laravel project but I get an internal server error 500 all the time, when I click on some link/route. I strongly believe it's the .htaccess file. The default file looks like this and I have no idea how I need to modify it.
On my ftp server I set it up like this:
The webspace is connected to /raidsystem/public_html/
The .htaccess is inside the _public_html_ and the other folder is called 'lsapp' which is in /raidsystem/, so it looks like this:
/raidsystem/lsapp/
/raidsystem/public_html/.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]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
In your conditions
Your index.php file in raidsystem/public_html/ needs to change
require __DIR__.'/lsapp/bootstrap/autoload.php';
AND
$app = require_once __DIR__.'/lsapp/bootstrap/app.php';
Related
I have Wordpress apps inside Laravel. This is what it's looks like.
public
--article
WordPress inside article folder. The reason I do this because I want it to access WordPress like this
{host}/article
There is issue occured. I can access {host}/article/wp-login.php. But when I fill The Login Form out and then send it, I got Laravel 404 Not Found Error Page.
This is weird because several days ago I can do that, but now error occured.
I think I miss some configurations in the .htaccess but I don't know the error.
This is my Laravel .htaccess configuration
# 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]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
and this is my WordPress .htaccess
# public/article/.htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteOptions inherit
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /article/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /article/index.php [L]
</IfModule>
I have a Laravel 7 project and I'm using XAMPP for my localhost. The project folder is in C:\xampp\htdocs\eegore-new. I've copied my .htaccess file from the public folder (the other one still exist in public directory), and put it in to the root directory and changed the server.php into index.php so I can now access my my application via localhost with this url -> http:://localhost/eegore-new. But once I clicked my login button on that page, it redirected me to http:://localhost/login which shows 'Object Not Found, Error 404' while it should redirected me to http:://localhost/eegore-new/login so the page can load correctly.
I've changed my APP_URL in .env file to <'http:://localhost/eegore-new-copy'> and tried to change my .htaccess file in my root folder.
This is my folder structure :
My folder structure screenshot
This is the .htaccess in my root folder, I tried RewriteBase but its not working:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
RewriteBase /eegore-new/
# 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>
And this is the .htacess in my public folder:
<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 have to make all the routes functioning just like http::/localhost/eegore-new/login or /user or /other but I'm not really sure what to do or where to start actually and I know nothing about .htaccess.
Any help will be really appreciated, thanks in advance!
When filling on hosting, I faced the problem that you can not select the start folder of the opening. When opening a link юhttps://my-domen/ this opens
to get to the site, enter /public
how to make sure that when you open the site, the public folder is immediately opened on the hosting so you can not configure it . Can I use htaccess or something else? If this helps then the laravel files are a clean project
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]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
In your root folder use this .htaccess:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
In the public folder use the new clean laravel .htaccess file
I have created Laravel CRUD API and it works fine in localhost(without .htaccess file), but it fails on the live server. When I send a request it returns 404 not found error, or downloads a file depending on .htaccess content. How should I change .htaccsess file for makeing code to work.
this is my .htaccess file which returns not found error.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
There is an 'official' htaccess that should provide you with the basic code to get this working.
See https://github.com/laravel/laravel/blob/master/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>
Then, simply make sure that the root points to yourproject/public so it can boot only from yourproject/public/index.php.
In my Dev server which is on my pc, I set up vhost to change my URL to dmb.dev to remove the public in URL so many of my routes started at / slash. After I transfer my project to our test server I configure some settings to allow me to remove public. Now, all assets are working except my routes because I'm still having http://server/dmb instead of http://server I'm getting an error of Failed to load resource: /myurl.
My sample routes
Route::get('/', 'PagesController#index')->name('index');
Route::get('/generate_bing', 'PagesController#generateImage')->name('index.getImage');
Route::get('/users', 'PagesController#showUser')->name('users')->middleware('auth','role:owner');
My root htaccess
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# 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]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>
Do I need to change all routes to dmb/etc.. I'm thinking of solution of removing my root folder so it would look like http://server, but there's other project on our htdocs so I need to remain it store in their folders. BTW I'm using xampp
As you have dmb as your folder under public_html, adding one line to your htaccess would solve the issue.
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
RewriteBase /dmb/ // ADD THIS LINE HERE
# 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]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>