Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Zend Framwork 2中从.htaccess重写到web.config的URL_.htaccess_Azure_Url Rewriting_Web Config_Zend Framework2 - Fatal编程技术网

在Zend Framwork 2中从.htaccess重写到web.config的URL

在Zend Framwork 2中从.htaccess重写到web.config的URL,.htaccess,azure,url-rewriting,web-config,zend-framework2,.htaccess,Azure,Url Rewriting,Web Config,Zend Framework2,我使用Zend Framework 2在PHP中开发应用程序。一切都在本地工作(linux上的apache服务器) 但现在我必须将我的站点部署到Windows服务器(在Azure上使用IIS) 由于IIS不读取.htaccess,我必须在web.config文件中重写它。这就是我使用IIS7导入重写规则功能所做的 不幸的是,ISS无法将规则转换为web配置 这就是我需要你帮助的地方 这是我的.htaccess文件(Zend Framework 2的默认文件) 编辑 经过一些研究,我发现-s和-l

我使用Zend Framework 2在PHP中开发应用程序。一切都在本地工作(linux上的apache服务器)

但现在我必须将我的站点部署到Windows服务器(在Azure上使用IIS)

由于IIS不读取.htaccess,我必须在web.config文件中重写它。这就是我使用IIS7导入重写规则功能所做的

不幸的是,ISS无法将规则转换为web配置

这就是我需要你帮助的地方

这是我的.htaccess文件(Zend Framework 2的默认文件)

编辑 经过一些研究,我发现-s和-l(前两个条件)可以替换为-f。太好了

所以我真正的问题在于最后两条规则。(ISS可以转换E=…和ENV:…语法)

来自ZF2文档:

如果将IIS与URL重写模块一起使用,请导入以下内容:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^.*$ index.php [NC,L]
您尝试过这个吗?

来自ZF2文档:

如果将IIS与URL重写模块一起使用,请导入以下内容:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^.*$ index.php [NC,L]

你试过了吗?

好的,这是我的最终解决方案。 一切正常,并符合我的期望(我添加了一个事实,即我不想在URL中看到/public)

阅读代码注释以便更好地理解

<!-- Rewrite rules -->
<!-- Below is some rules in order to have a beautiful URL on the client side.
    + Each requests to a /public/something urls are transferred to a /something url
    + If the /public/requestFile exists we serve it
    + If the requested file exists  we serve it
    + If no other rules has matched then we send the request to our public/index.php file             (default behavior from Zend Framework 2)
-->
<rewrite>
  <rules>
    <!-- Permanent redirect of requests on /public/something to /something -->
    <rule name="Redirect public " stopProcessing="true">
      <match url="^public/(.*)$" ignoreCase="false" />
      <action type="Redirect" redirectType="Permanent" url="/{R:1}" />
    </rule>

     <!-- If the file/directory requested exist in /public, we serve it. -->
    <rule name="Search in public" stopProcessing="true">
      <match url="^(.*)$" ignoreCase="false" />
      <conditions logicalGrouping="MatchAny">
        <add input="{DOCUMENT_ROOT}/public{URL}" matchType="IsFile" ignoreCase="false" />  
        <add input="{DOCUMENT_ROOT}/public{URL}" matchType="IsDirectory" ignoeCase="false" />
      </conditions>
      <action type="Rewrite" url="/public/{R:1}" />
    </rule>

    <!-- If the file/directory requested exist, we serve it. -->
    <rule name="Direct files" stopProcessing="true">
      <match url="^.*$" />
      <conditions logicalGrouping="MatchAny">
        <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="true" />
        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="true" />
      </conditions>
      <action type="None" />
    </rule>

    <!-- If no previous rules have matched, then we send the request to public/index (url rewriting
        used by Zend -->
    <rule name="Url rewriting" stopProcessing="true">
    <match url="^.*$" />
      <conditions>
        <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
      </conditions>
      <action type="Rewrite" url="public/index.php" />
    </rule>
  </rules>
</rewrite>


感谢鲁本的帮助

好的,这是我的最终解决方案。 一切正常,并符合我的期望(我添加了一个事实,即我不想在URL中看到/public)

阅读代码注释以便更好地理解

<!-- Rewrite rules -->
<!-- Below is some rules in order to have a beautiful URL on the client side.
    + Each requests to a /public/something urls are transferred to a /something url
    + If the /public/requestFile exists we serve it
    + If the requested file exists  we serve it
    + If no other rules has matched then we send the request to our public/index.php file             (default behavior from Zend Framework 2)
-->
<rewrite>
  <rules>
    <!-- Permanent redirect of requests on /public/something to /something -->
    <rule name="Redirect public " stopProcessing="true">
      <match url="^public/(.*)$" ignoreCase="false" />
      <action type="Redirect" redirectType="Permanent" url="/{R:1}" />
    </rule>

     <!-- If the file/directory requested exist in /public, we serve it. -->
    <rule name="Search in public" stopProcessing="true">
      <match url="^(.*)$" ignoreCase="false" />
      <conditions logicalGrouping="MatchAny">
        <add input="{DOCUMENT_ROOT}/public{URL}" matchType="IsFile" ignoreCase="false" />  
        <add input="{DOCUMENT_ROOT}/public{URL}" matchType="IsDirectory" ignoeCase="false" />
      </conditions>
      <action type="Rewrite" url="/public/{R:1}" />
    </rule>

    <!-- If the file/directory requested exist, we serve it. -->
    <rule name="Direct files" stopProcessing="true">
      <match url="^.*$" />
      <conditions logicalGrouping="MatchAny">
        <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="true" />
        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="true" />
      </conditions>
      <action type="None" />
    </rule>

    <!-- If no previous rules have matched, then we send the request to public/index (url rewriting
        used by Zend -->
    <rule name="Url rewriting" stopProcessing="true">
    <match url="^.*$" />
      <conditions>
        <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
      </conditions>
      <action type="Rewrite" url="public/index.php" />
    </rule>
  </rules>
</rewrite>


感谢鲁本的帮助

很好,很高兴成功了。您是否必须手工编写规则,或者IIS的导入功能是否像文档所建议的那样解决了大部分繁重的工作?不,我在IIS中使用了导入功能来创建一些规则。然后我做了一些更新来满足我的需要。但是你的建议帮了大忙!顺便说一句,我从未在文档中看到过URL重写的引用?它在《入门指南》中,就在页面底部:很好,很高兴它成功了。您是否必须手工编写规则,或者IIS的导入功能是否像文档所建议的那样解决了大部分繁重的工作?不,我在IIS中使用了导入功能来创建一些规则。然后我做了一些更新来满足我的需要。但是你的建议帮了大忙!顺便说一句,我从来没有在文档中看到过URL重写的引用?它在《入门指南》中,就在页面底部:非常感谢您的帮助。这是找到最终解决方案的一个非常好的开始!非常感谢你的帮助。这是找到最终解决方案的一个非常好的开始!