Laravel Shared Hosting Htaccess

Laravel Shared Hosting Htaccess is the easiest and most effective way to set up a Laravel environment. It includes everything you need to build your websites. Our shared hosting platform is backed by reliable 24/7 support and provided on our hyper-fast servers.

Laravel Shared Hosting Htaccess

I am trying to deploy a Laravel project onto a share hosting, I’ve managed to get most of the hard work done but I cannot strip off the /public directory without a Forbidden issue.

The website works and shows same pages for these links

  • www.mywebsite.com/test/index.php
  • www.mywebsite.com/test/public/

But without the /index.php It returns ->

Forbidden

You don't have permission to access /test/ on this server. 

Currently my .htaccess looks like the following.

<IfModule mod_rewrite.c>

    RewriteEngine On

    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ public/index.php [L]

</IfModule>

Any ideas?

  • php
  • apache
  • .htaccess
  • mod-rewrite
  • laravel

Share

Improve this questionFollow

asked Aug 4, 2014 at 13:10

Brent

2,28599 gold badges3737 silver badges6262 bronze badges

  • So www.mywebsite.com/test/public/ works but www.mywebsite.com/test/ doesn’t? – anubhava Aug 4, 2014 at 13:12
  • www.mywebsite.com/test/index.php works though, so I believe something incorrect with my .htaccess – Brent Aug 4, 2014 at 13:13

Add a comment

4 Answers

Sorted by:                                              Highest score (default)                                                                   Trending (recent votes count more)                                                                   Date modified (newest first)                                                                   Date created (oldest first)                              

7

Try this rule in test/.htaccess:

DirectoryIndex index.php
<IfModule mod_rewrite.c>

    RewriteEngine On
    RewriteBase /test/

    RewriteRule ^$ public/index.php [L]

    RewriteRule ^((?!public/).*)$ public/$1 [L,NC]

</IfModule>

Share

Improve this answerFollow

edited Aug 4, 2014 at 13:41

answered Aug 4, 2014 at 13:14

anubhava

733k6262 gold badges533533 silver badges613613 bronze badges

  • 1Thanks for quick reply 🙂 This kind-of works it produces a NotFoundHttpException where as index.php displays the website? – Brent Aug 4, 2014 at 13:17 
  • Yes but www.mywebsite.com/test/index.php works and also www.mywebsite.com/test/public works – Brent Aug 4, 2014 at 13:19
  • Not Found – The requested URL /test/index.php was not found on this server. – Brent Aug 4, 2014 at 13:30 
  • Would team-viewer be easier? – Brent Aug 4, 2014 at 13:35
  • Same again unfortunately. – Brent Aug 4, 2014 at 13:46

Show 1 more comment

7

this is the magic script i use (add to the .htaccess in public_html)

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>

Share

Improve this answerFollow

answered Jun 1, 2020 at 17:36

The Billionaire Guy

3,1422727 silver badges2929 bronze badges

  • Thanks. It worked for me. Tried lot of things. Nothing worked. – Umair Sep 25, 2021 at 14:05
  • 2If on a web server it is not working, then add RewriteBase like this RewriteEngine On RewriteBase / RewriteRule ^(.*)$ public/$1 [L] – Umair Sep 25, 2021 at 14:09 

Add a comment

3

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteRule ^$ public/index.php [L]
    RewriteRule ^((?!public/).*)$ public/$1 [L,NC]
</IfModule>

Share

Improve this answerFollow

edited Jan 21 at 19:51

RavinderSingh13

124k1313 gold badges5151 silver badges8989 bronze badges

answered Jan 21 at 16:50

Việt Nam Sea Lions

3111 bronze badge

  • 1This looks very similar to the top answer. Why do it this way? – General Grievance Jan 22 at 6:33

Add a comment

0

This script is working for me.

<IfModule mod_rewrite.c>
   RewriteEngine On
   # Force SSL
   RewriteCond %{HTTPS} !=on
   RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
   # Remove public folder form URL
   RewriteRule ^(.*)$ public/$1 [L]

how to deploy laravel project on cpanel subdomain

4 Answer

  1. Create your sub-domain.
  2. Upload your laravel project to the sub-domain home directory.
  3. After you have uploaded all the files. Update your sub-domain document-root to point to public_html/registration/public/ folder, you can do this from sub-domain manager inside cPanel see.

Leave a Comment