简体   繁体   中英

Following an AngularJS/MySQL/PHP tutorial. Having trouble converting the given .HTACCESS file to an equivalent 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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM