403 Forbidden Access on SubDomain (cPanel & Litespeed Web Server). I am now trying to deploy a Laravel project on a subdomain of shared hosting with cPanel (LItespeed Web Server).
Created a subdomain (subdomain.example.com)
Uploaded a Laravel project on it
Can access the project via subdomain.example.com/public/index.php
Can't access the project via subdomain.example.com (403 Forbidden)
I tried adding a .htaccess file at the root directory (of subdomain.example.com)
<IfModule>
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ public/index.php [L]
</IfModule>
Nothing changes after the update of .htaccess and it just keeps working the same.
(I would like to solve this with .htaccess only. SO, please help me with this, guys. Thanks)
I normally would configure the subdomain directory in cPanel like follow:
/public_html/subdomain.example.com/public/
this way when you access subdomain.example.com it would work out of the box and you keep project structure, and no .htaccess configuration needed.
@momagdi Thanks for your reply. I already tried that. It doesn't work properly. If I go with this, I can't get access to subdomain.example.com/dashboard though other urls are working fine (also images from storage are returning 404 - I already run php artisan storage:link). I don't know why. That's why I included that I only want to go with .htaccess. Maybe it's also good if the cpanel solution works fine.
I tried to access the subdomain.example.com/dashboard but it automatically redirects to subdomain.example.com/public/dashboard and displays 404 error.
@momagdi and what do you get at /public_html/subdomain.example.com/.env ??????
@Snapey btw, in my cPanel, subdomain directory is not under public_html. The directory is separately created under username 'subdomain.example.com'.
@Snapey
APP_NAME=Applica
APP_ENV=local
APP_KEY=base64:4qXUWGJoxaEOhIEOx6DrrM+4bSLkJAc80txrGAwcsW8=
APP_DEBUG=true
APP_URL=http://applica.test
if you want to solve the application URL issue via .htaccess, add the following to your (laravel) root directory:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?subdomain.example.com$
RewriteCond %{REQUEST_URI} !^/public/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /public/
RewriteCond %{HTTP_HOST} ^(www.)?subdomain.example.com$
RewriteRule ^(/)?$ public/index.php [L]
this will set /public as the root directory for the application.
Please sign in or create an account to participate in this conversation.