目前我正在用 PHP 开发一个网上商店。为此,我使用 Zend Framework 2。
我的所有路由都存在一个语言环境,即“nl_NL”或“en_EN”,后跟一个控制器和一个操作 www.mydomain.com/nl_NL/profile/login。在此处查看我的项目中使用的路线示例。这个属于配置文件模块: http: //pastebin.com/jmim47w8。
如果访问者没有帐户,也没有设置 Cookie,则首先将 locale 变量设置为从以下函数中检索到的变量:
locale_accept_from_http($_SERVER['HTTP_ACCEPT_LANGUAGE'])
如果设置了 cookie,则将使用该值。另一方面,如果用户确实有一个帐户并已登录,则使用的变量将从用户的配置文件中检索。
我的整个脚本在本地主机上运行。但是,在服务器上却没有。加载页面时没有显示任何内容。我检查了错误日志,找不到任何东西。但是,当我在 url 中手动放置 /nl_NL/ 或任何其他满足“语言环境路由”正则表达式要求的语言环境时,它确实有效。
我的第一个想法是 url_rewrite apache 模块没有安装或激活,但由于其他网站也使用这个模块,而且它们在同一台服务器上,这似乎不合逻辑。当然,我确实尝试通过运行一些脚本来检查它是否已启用,但无济于事。由于我们的服务器设置为不允许运行 shell 脚本,或者使用 phpinfo() 检查是否启用了 apache 模块,因此很难确定。
我试图验证我的 .htaccess 文件是否正确,但我几乎是 .htaccess 的菜鸟。这是我的 .htaccess:
RewriteEngine On
# The following rule tells Apache that if the requested filename
# exists, simply serve it.
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
# The following rewrites all other queries to index.php. The
# condition ensures that if you are using Apache aliases to do
# mass virtual hosting, the base path will be prepended to
# allow proper resolution of the index.php file; it will work
# in non-aliased environments as well, providing a safe, one-size
# fits all solution.
RewriteCond %{REQUEST_URI}::$1 ^(/.+)(.+)::\2$
RewriteRule ^(.*) - [E=BASE:%1]
RewriteRule ^(.*)$ %{ENV:BASE}index.php [NC,L]
要查看我的 IndexController 的样子,请看这里: http: //pastebin.com/AEgm3Jmk。
总而言之,我真的很想知道如何让 Zend FW 2 项目在托管服务器上工作,同时仍然使用 url 重写或任何其他可以使用语言环境变量的方式。
如果这篇文章中缺少一些需要进一步帮助我的东西,我很乐意发布它。