Search code examples
.htaccesscomposer-phppackagist

.htaccess for packagist where you can't choose web as webroot


I was installing packagist, a symfony2 app, and ran into a situation where I couldn't set the webroot as the 'web' directory. Because I didn't want to have to type /web/ or /web/app.php, I needed an .htaccess to accomodate this situation, including the json files it dumps in the p subdirectory.


Solution

  • This is the .htaccess I used.

    ``` Options +FollowSymlinks RewriteEngine On

    # Explicitly disable rewriting for front controllers
    RewriteRule ^/web/app_dev.php - [L]
    RewriteRule ^/web/app.php - [L]
    
    # Fix the bundles folder
    RewriteRule ^bundles/(.*)$ /web/bundles/$1  [QSA,L]
    RewriteRule ^p/(.*)$ /web/p/$1  [QSA,L]
    
    RewriteCond %{REQUEST_FILENAME} !-f
    # Change below before deploying to production
    RewriteRule ^(.*)$ /web/app.php [QSA,L]
    #RewriteRule ^(.*)$ /web/app_dev.php [QSA,L]
    

    ```