9

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?

2
  • 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

4 Answers 4

18

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>
2
  • Thanks. It worked for me. Tried lot of things. Nothing worked.
    – Umair
    Sep 25, 2021 at 14:05
  • 3
    If 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
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>
6
  • 1
    Thanks 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
4
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteRule ^$ public/index.php [L]
    RewriteRule ^((?!public/).*)$ public/$1 [L,NC]
</IfModule>
1
  • 1
    This looks very similar to the top answer. Why do it this way? Jan 22, 2022 at 6:33
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]
</IfModule>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.