Symfony4 routing inside a subfolder

前端 未结 2 704
闹比i
闹比i 2020-12-22 10:00

I have a symfony app in my /var/www/html/app/ and I\'d like to access it via host/app/ but I can\'t make it work.

I have a conf fil         


        
2条回答
  •  太阳男子
    2020-12-22 10:12

    I managed to resolve the problem !!!

    I'm not sure the config is "proper" though but it seems to work.

    Here is my working app.conf file (in /etc/apache2/sties-enabled/app.conf)

    Alias /app "/var/www/html/app/public"
    
    
    
        AllowOverride None
        Order Allow,Deny
    
        Allow from All
    
        
    
            Options -MultiViews
            RewriteEngine On
    
            RewriteRule (/public) - [L]
    
            RewriteCond %{REQUEST_FILENAME} !-f
            RewriteCond %{REQUEST_FILENAME} !-d
    
            RewriteRule ^(.*)$ index.php/$1 [L]
    
        
    
    

    The first RewriteRule is to prevent from internal Rewrite loop when I rewrite url like example.com/app/page-1 to example.com/app/public/index.php/page-1. As page-1 is not a directory or a file it will loop infinitely. So I assume as soon as I have a /public part, the rewrite worked and we stop the rewrite by doing nothing and end the rewrite with the [L] flag.

    I'm not suire why I had to remove the public/ part in the "final" RewriteRule (RewriteRule ^(.*)$ index.php/$1 [L]) though.

    If someone have ideas to improve this config, feel free to leave comment.

提交回复
热议问题