Yii2 Heroku - You don't have permission to access /frontend/web/ on this server.

I have an application that has 3 sections - frontend, backend & portal. I have a .htaccess file with rewrite rules for the three sections so they resolve to; ‘/’, ‘/admin’ & ‘/portal’ respectively. This configuration works on my local machine just fine but when it’s deployed on Heroku and I visit the site root I get the error: You don’t have permission to access /frontend/web/ on this server.

The rewrite rules are working as I am redirected to the correct uri but there seems to be a permission error that I don’t understand.

I’ve checked out the logs and this is the error that is thrown:


Cannot serve directory /app/frontend/web/: No matching DirectoryIndex (index.php,index.html,index.htm) found, andserver-generated directory index forbidden by Options directive

Below is my .htaccess file. Any help would be really appreciated, I’m struggling to figure this one out.


Options FollowSymLinks

AddDefaultCharset utf-8


<IfModule mod_rewrite.c>

    RewriteEngine On


    # the main rewrite rule for the frontend application

    RewriteCond %{REQUEST_URI} !^/(backend/web|admin|portal/web|portal)

    RewriteRule !^frontend/web /frontend/web%{REQUEST_URI} [L]


    # redirect to the page without a trailing slash (uncomment if necessary)

    #RewriteCond %{REQUEST_URI} ^/admin/$

    #RewriteRule ^(admin)/ /$1 [L,R=301]

    # the main rewrite rule for the backend application

    RewriteCond %{REQUEST_URI} ^/admin

    RewriteRule ^admin(.*) /backend/web/$1 [L]


    # redirect to the page without a trailing slash (uncomment if necessary)

    #RewriteCond %{REQUEST_URI} ^/admin/$

    #RewriteRule ^(admin)/ /$1 [L,R=301]

    # the main rewrite rule for the backend application

    RewriteCond %{REQUEST_URI} ^/portal

    RewriteRule ^portal(.*) /portal/web/$1 [L]


    # if a directory or a file of the frontend application exists, use the request directly

    RewriteCond %{REQUEST_URI} ^/frontend/web

    RewriteCond %{REQUEST_FILENAME} !-f

    RewriteCond %{REQUEST_FILENAME} !-d

    # otherwise forward the request to index.php

    RewriteRule . /frontend/web/index.php [L]


    # if a directory or a file of the backend application exists, use the request directly

    RewriteCond %{REQUEST_URI} ^/backend/web

    RewriteCond %{REQUEST_FILENAME} !-f

    RewriteCond %{REQUEST_FILENAME} !-d

    # otherwise forward the request to index.php

    RewriteRule . /backend/web/index.php [L]


    # if a directory or a file of the backend application exists, use the request directly

    RewriteCond %{REQUEST_URI} ^/portal/web

    RewriteCond %{REQUEST_FILENAME} !-f

    RewriteCond %{REQUEST_FILENAME} !-d

    # otherwise forward the request to index.php

    RewriteRule . /portal/web/index.php [L]


    RewriteCond %{REQUEST_URI} \.(htaccess|htpasswd|svn|git)

    RewriteRule \.(htaccess|htpasswd|svn|git) - [F]

</IfModule>

Hi Robert - could you tell me how you fixed this? Same conditions here…thank you :wink: