URL rewrite doesn't work in a Symfony2

戏子无情 提交于 2020-01-06 18:07:13

问题


I have a web site under Symfony 2 and want to have a basic URL rewrite.

Apache mod rewrite is enabled. Apache has been restarted multiple times.

# a2enmod rewrite
Module rewrite already enabled

Virtual host seems ok

<VirtualHost *:80>
    ServerName mydomain.com
    ServerAlias www.mydomain.com

    DocumentRoot /home/www/mydomain/web
    <Directory />
        Options FollowSymLinks
        AllowOverride None
    </Directory>
    <Directory /home/www/mydomain/web>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride None
        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>

And here's my .htacess

<IfModule mod_rewrite.c>
    RewriteEngine On

    #<IfModule mod_vhost_alias.c>
    #    RewriteBase /
    #</IfModule>

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ app.php [QSA,L]
</IfModule>

But http://mydomain.com/ gives the "index of" page and I have to pass through http://mydomain.com/app.php/ to access my web site.

What am I missing ?!!


回答1:


You need to change AllowOverride None to AllowOverride All

When this directive is set to None and AllowOverrideList is set to None .htaccess files are completely ignored. In this case, the server will not even attempt to read .htaccess files in the filesystem.

When not specified, AllowOverrideList is set to None

http://httpd.apache.org/docs/current/mod/core.html#allowoverride



来源:https://stackoverflow.com/questions/16548131/url-rewrite-doesnt-work-in-a-symfony2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!