skip to Main Content

when i visit localhost/project I get this error

Forbidden

You don't have permission to access this resource.
Apache/2.4.29 (Ubuntu) Server at localhost Port 80

when i try to access project root directory, my index.php is in public folder (project/public/index.php) so i use .htaccess to redirect requests to public folder but this doesn’t seem to work
i tried to set AllowOverride All but didn’t help
i tried to change all project permissions even to 777 still didn’t work

here is my .htaccess

<IfModule mod_rewrite.c>
    RewriteEngine On

    RewriteCond %{THE_REQUEST} /public/([^s?]*) [NC]
    RewriteRule ^ %1 [L,NE,R=302]

    RewriteRule ^((?!public/).*)$ public/$1 [L,NC]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ /index.php?/$1 [L]

</IfModule>

i am using ubuntu 18.08 – PHP 7.3 – Apache

2

Answers


  1. Just put this in your project folder .htaccess

    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteRule ^([^/.]*)/?$ public/index.php?%{QUERY_STRING} [L]
    </IfModule>
    
    Login or Signup to reply.
  2. You can have this in /project/.htaccess:

    RewriteEngine On
    
    RewriteCond %{THE_REQUEST} /public/([^s?]*) [NC]
    RewriteRule ^ /project/%1 [L,NE,R=301]
    
    RewriteRule ^(.*)$ public/$1 [L,NC]
    

    Then have this rule in project/public/.htaccess:

    RewriteEngine On
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?/$1 [L]
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search