.htaccess - Zend Framework 2 中从 .htaccess 到 web.config 的 URL 重写

标签 .htaccess azure url-rewriting web-config zend-framework2

我正在使用 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/

相关文章:

php - .htaccess 在动态文件夹名称中加载索引

mysql - 如何将我的重写规则存储在数据库中?

本地运行的Azure Blob触发器函数处理容器中的所有文件

node.js - 从 OSX 命令行发布 azure 网站?

apache - 将参数url重写为普通url,但重定向后应该获取原始url参数

.htaccess 仅适用于特定文件夹脚本

php - 从 php 和 sql 创建动态自动递增的 seo 友好 url

Azure - 网站在 RDP 文件系统中存储在哪里?

seo - 使网址友好的最佳方法?

tomcat - URLRewriteFIlter,如何删除上下文/文件夹名称?