How to remove “web/app_dev.php” from Symfony2 URLs?

前端 未结 7 972
误落风尘
误落风尘 2020-12-13 07:01

I just created my first Symfony2 project. But the \"/web/app_dev.php\" part in the URL annoys me. It should be possible to do this without Virtual hosts...

相关标签:
7条回答
  • 2020-12-13 08:05

    I used to have this problem too, please take a look at my configurations and try them out

    inside my .htaccess:

    Hi all, I have been having this problem too. And it seems that the "stock" .htaccess is the problem. I have solved this in my environment and here is my .htaccess with notes:

    <IfModule mod_rewrite.c>
        RewriteEngine On
        RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
        RewriteRule ^(.*) - [E=BASE:%1]
        RewriteCond %{ENV:REDIRECT_STATUS} ^$
        RewriteRule ^app_dev.php(/(.*)|$) %{ENV:BASE}/$2 [R=301,L]    ##### this is the part that you     should tweak, have the .htaccess point the request to app_dev.php, since the routing.yml is empty initially
        RewriteCond %{REQUEST_FILENAME} -f
        RewriteRule .? - [L]
        RewriteRule .? %{ENV:BASE}/app_dev.php [L]        ##### this is the part that you should tweak, have the .htaccess point the request to app_dev.php, since the routing.yml is empty initially
    </IfModule>
    
    <IfModule !mod_rewrite.c>
        <IfModule mod_alias.c>
            # When mod_rewrite is not available, we instruct a temporary redirect of
            # the startpage to the front controller explicitly so that the website
            # and the generated links can still be used.
            RedirectMatch 302 ^/$ /app.php/
            # RedirectTemp cannot be used instead
        </IfModule>
    </IfModule>
    

    inside my "symfony" entry in /etc/apache2/sites-available:

    <VirtualHost 127.0.1.15>
        ServerAdmin webmaster@localhost
        ServerName symfony
        DocumentRoot /var/www/Symfony/web
        DirectoryIndex app.php
        <Directory /var/www/Symfony/web>
            Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        allow from all
    </Directory>
    
    ErrorLog ${APACHE_LOG_DIR}/error.log
    # Possible values include: debug, info, notice, warn, error, crit,
    # alert, emerg.
    LogLevel warn
    CustomLog ${APACHE_LOG_DIR}/access.log combined
    </VirtualHost>
    
    0 讨论(0)
提交回复
热议问题