doulaozhi6835 2013-08-26 02:27
浏览 45
已采纳

URL重写不适用于ZF和apache2

This has got me baffled. I recently set up VM in a hurry to go travelling. I installed Ubuntu 12.04 and LAMP. The PHP version is 5.5 and Apache is 2.4. I have used this same configuration on my home machine and it works fine.

Anyhow, the problem is that I can only access actions on the index controller of my ZF application, e.g: domainname/, domainname/index/info. If I try any other controllers, e.g. domainname/test/view, I get the apache 404 error. (Note - NOTE the ZF Not Found error).

I imagine this is a problem with URL rewriting, but the .htaccess on my VM is the same as my home machine, and I can't see anything in the virtual host configuration that would cause this. Also, if it was simply an URL rewriting problem, I would have thought it would come in to play for ALL urls, including the index controller...

Here's my htaccess:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]

Ideas?

EDIT: Here's the virtual host config:

DocumentRoot /home/kim/www/vhost/public ServerName koop SetEnv APPLICATION_ENV "development"

<Directory /home/kim/www/vhost/public>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride None
            Require all granted
</Directory>

ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined

  • 写回答

1条回答 默认 最新

  • duandan5471 2013-08-26 05:44
    关注

    Ok, so I had to change AllowOverride to All. That means Apache2 will now process my .htaccess files.

    Then I needed to enable mod rewrite, by sudo a2enmod rewrite, then restart apache, i.e. sudo service apache2 restart

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?