JimB814 JimB814 - 2 months ago 17
Apache Configuration Question

how to configure htaccess file if main controller resides in public folder

I saw a near identical question to mine, but the accepted answer doesn't work for some reason.

My problem is that I cannot access index.php which sits inside a public folder. I have tried innumerable combinations and believe that it's in the correct folder -- the public folder.

The answer that didn't work was to make the ReWriteBase %{DOCUMENT_ROOT}/public. I did that but get an Index of. At least the public folder is not visible, however, so it feels like I'm getting close.

Any help is appreciated.

PS. I can see the application on my local machine with RewriteBase /projectname/public but the URL must include public or I get an Index of page. I want to be rid of the public portion and work off the root (domain name).

Here is my .htaccess file:

Options -MultiViews
RewriteEngine On
RewriteBase %{DOCUMENT_ROOT}/public
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]


Updated htaccess file:

Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /public/

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]

Answer

RewriteBase is supposed to be relative path from DocumentRoot not full path.

Here are 2 .htaccess you need to use:

root/.htaccess:

RewriteEngine On

RewriteRule .* public/$0 [L]

public/.htaccess:

DirectoryIndex index.php
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /public/

RewriteRule ^index\.php$ - [L,NC]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* index.php?url=$0 [QSA,L]