简体   繁体   English

URL重写不适用于ZF和apache2

[英]URL Rewriting not working with ZF and apache2

This has got me baffled. 这让我感到困惑。 I recently set up VM in a hurry to go travelling. 我最近急着要设置VM。 I installed Ubuntu 12.04 and LAMP. 我安装了Ubuntu 12.04和LAMP。 The PHP version is 5.5 and Apache is 2.4. PHP版本是5.5,Apache版本是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, eg: domainname/, domainname/index/info. 无论如何,问题在于我只能访问我的ZF应用程序的索引控制器上的操作,例如:domainname /,domainname / index / info。 If I try any other controllers, eg domainname/test/view, I get the apache 404 error. 如果尝试其他任何控制器,例如域名/测试/视图,则会收到apache 404错误。 (Note - NOTE the ZF Not Found error). (注意-注意ZF Not Found错误)。

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. 我以为这是URL重写的问题,但是我的VM上的.htaccess与我的家用计算机相同,并且我在虚拟主机配置中看不到任何会导致此问题的内容。 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... 另外,如果这仅仅是一个URL重写问题,我会以为它将用于所有URL,包括索引控制器。

Here's my htaccess: 这是我的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" DocumentRoot / home / kim / www / vhost / public ServerName koop SetEnv APPLICATION_ENV“开发”

<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

Ok, so I had to change AllowOverride to All. 好的,所以我不得不将AllowOverride更改为All。 That means Apache2 will now process my .htaccess files. 这意味着Apache2现在将处理我的.htaccess文件。

Then I needed to enable mod rewrite, by sudo a2enmod rewrite , then restart apache, ie sudo service apache2 restart 然后我需要通过sudo a2enmod rewrite启用mod rewrite,然后重新启动apache,即sudo service apache2 restart

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM