Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

synerops's avatar

Laravel in sub-folder

im trying to upload laravel in sub-directory (static site no database) home page load fine but other pages like about, services throw error Internal Server Error. laravel.log and error_log are empty its load path currently www.example.com/laravel/about .htaccess and index.php from public folder have move to root folder www.example.com/laravel

.htaccess: <IfModule mod_rewrite.c> RewriteEngine On RewriteBase /laravel/
RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ public/$1 [L] </IfModule>

index.php: use Illuminate\Http\Request;

define('LARAVEL_START', microtime(true));

// Determine if the application is in maintenance mode... if (file_exists($maintenance = DIR.'/storage/framework/maintenance.php')) { require $maintenance; }

// Register the Composer autoloader... require DIR.'/vendor/autoload.php';

// Bootstrap Laravel and handle the request... (require_once DIR.'/bootstrap/app.php') ->handleRequest(Request::capture());

config/app.php 'url' => env('APP_URL', 'http://www.example.com/laravel'),

env file APP_DEBUG=true APP_URL=http://www.example.com/laravel APP_ENV=local (change production also)

DB_CONNECTION=mysql

DB_HOST=127.0.0.1

DB_PORT=3306

DB_DATABASE=leeshow

DB_USERNAME=root

DB_PASSWORD=

SESSION_DRIVER=array

web.php Route::get('/', function () { return view('home'); })->name('home');

Route::get('/about', function () { return view('about'); })->name('about');

views/component/layout.blade.php for menu: About

Home page loads fine but about and other pages show Internal Server Error as laravel.log and error_log are empty

0 likes
9 replies
jlrdw's avatar

.htaccess and index.php from public folder have move to root folder

I suggest you correctly setup the folder structure and point to public as the document root.

1 like
sm3rter's avatar

If your application is entirely static, there's no need to use Laravel. Static sites don’t require server-side logic or dynamic content generation, so a simpler static site generator or basic HTML/CSS/JS setup would be sufficient

Also if you need to implement some logic, you can simply use plain PHP without the overhead of a full Laravel framework. This approach can keep your application lightweight and straightforward

1 like
synerops's avatar

@sm3rter yes, i understand that but clients requirement is site should be in laravel even its static

puklipo's avatar

Always use Laravel in the root path of your domain. Never use it in a subdirectory.

When running a server, I found that there were many malicious attacks attempting to steal .env.
The main culprit behind the increase in these types of attackers are beginners who run it in a subdirectory.

1 like
synerops's avatar

@puklipo we show our design in sub-directory when client is satisfied then we move to clients domain as we are using share hosting which doesnt provide subdomain

azimidev's avatar

could be due to the .htaccess configuration or file path issues after moving the public folder's content to the sub-directory. While you can technically run Laravel in a sub-directory, it often requires careful configuration

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /laravel/  # Set the base URL to your sub-directory
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [L]  # Point requests to the correct index.php
</IfModule>
1 like
synerops's avatar

@azimidev as im new with laravel RewriteRule ^(.)$ index.php/$1 [L] this line gives me blank page may due to subfolder but RewriteRule ^(.)$ public/$1 [L] run home page but not others page as my hosting doesnt provide subdomain

sm3rter's avatar

Since you're using a shared hosting platform that doesn't support subdomains, a SIMPLE solution is to use symbolic links

Please or to participate in this conversation.