douxuexiao1748 2015-06-20 23:55
浏览 59

遵循AngularJS / MySQL / PHP教程。 无法将给定的.HTACCESS文件转换为等效的web.config

My goal is to create a simple web interface that will allow a user to view and interact with a small MySQL database (not much more than simple CRUD functionality).

After some research, I found this tutorial and began following it:

http://www.angularcode.com/product-inventory-management-using-angularjs-mysql-and-php-restful-api/

However, as everyone in the comment section will tell you, out-of-the-box it will not load. The creator of the tutorial told everyone to enable mod_rewrite on their web server and that would fix the issue. However, I'm using visual studio and IIS, not a local Apache server.

The .HTACCESS file given in the demo is as follows:

RewriteEngine On 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^(.*)$ %{ENV:BASE}index.php [QSA,L]

I assume (someone please correct me if I'm wrong, I am new at this), that I'll need to replicate that same functionality in my web.config file instead. My first attempt at this is here:

<configuration>
  <system.web>
    <compilation debug="true" targetFramework="4.5" />
    <httpRuntime targetFramework="4.5" />
  </system.web>
 <system.webServer>

  <rewrite>
    <rules>
      <rule name="Imported Rule 1" stopProcessing="true">
        <match url="^(.*)$" ignoreCase="false" />
        <conditions>
          <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />       
        </conditions>
        <action type="Rewrite" url="index.php?q={R:1}" appendQueryString="true" />
      </rule>
    </rules>
  </rewrite>

 </system.webServer>
</configuration>

However, this does not work. After making these changes, I now get a 404 ("Requested URL http://localhost:59438/index.php?q= ").

At this point I fear I have already spent more time than I should have fighting this portion of the tutorial that has little to nothing to do with the skills I'm attempting to practice (though I guess that is just par for the course).

If someone could take a look at what I'm doing wrong, or supply a workaround so I can actually get started with this, I would be eternally grateful.

  • 写回答

1条回答 默认 最新

  • douren1891 2015-06-21 09:38
    关注

    Your .htaccess and web.config rules differ.

    The RewriteRule you are using is designed to send the current request to index.php, without the use of a query string. However, your Rewrite action in web.config is rewriting the request to index.php?q=<something>, and I don't think that is the desired behaviour.

    As such, you should simply change the rule to:

    <action type="Rewrite" url="/index.php" appendQueryString="true" />
    
    评论

报告相同问题?

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效