我正在使用 Zend Framework 2 开发 PHP 应用程序。一切都在本地运行(Linux 上的 apache 服务器)。
但现在我必须将我的网站部署到 Windows Server(在 Azure 上使用 IIS)。
由于 IIS 无法读取 .htaccess,我必须将其重写到 web.config 文件中。这就是我使用 IIS7 导入重写规则功能所做的事情。 More informations here .
不幸的是 ISS 无法将规则转换为网络配置..
这就是我需要你帮助的地方。
这是我的 .htaccess 文件(Zend Framework 2 中的默认文件)
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]
编辑
经过一些研究,我发现 -s 和 -l (前两个条件)可以用 -f 代替。完美!
所以我真正的问题集中在最后两条规则上。 (ISS可以转换E=..和ENV:..语法)
最佳答案
来自 ZF2 文档:
如果您使用的是带有 URL 重写模块的 IIS,请导入以下内容:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^.*$ index.php [NC,L]
你试过这个吗?
关于.htaccess - Zend Framework 2 中从 .htaccess 到 web.config 的 URL 重写,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17754015/