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" />
    
    评论

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题