web.config中的URL重写不适用于子目录中的Slim PHP API [英] URL-rewriting in web.config not working for Slim PHP API in subdirectory
问题描述
我使用WAMP堆栈(Windows + Apache + MySQL + PHP)和SlimPHP微框架开发了后端应用程序。它与WAMP完美配合,但现在我必须在使用IIS v7.5的服务器上工作,我收到HTTP 404错误。
I developed the backend application using the WAMP stack (Windows + Apache + MySQL + PHP) and SlimPHP micro framework. It is working perfectly with WAMP but now I have to make it work in a server that is using IIS v7.5 and I'm getting an HTTP 404 error.
frontend是位于根目录下的AngularJS应用程序(这里没问题),它使用从位于/ api / v0子目录中的SlimPHP API获得的数据。
The frontend is an AngularJS application located in the root directory (no problem here) that uses the data obtained from the SlimPHP API located in the /api/v0 subdirectory.
这是我的网络应用程序的结构:
Here is the structure of my web-app:
Project
|--index.html
|--styles (directory with .css files)
|--views (directory with .html partial views for angularJS)
|--scripts (directory with .js angularJS scripts)
|--api
|--composer.json
|--vendor
|--autoload.php
|--slim (directory with slim framework files)
|--v0
|--index.php (SlimPHP application)
|--.htaccess (Apache configuration file)
|--web.config (ISS configuration file)
- .htaccess (Apache配置) http://pastebin.com/ZPrhcQiV
- .htaccess (config for Apache) http://pastebin.com/ZPrhcQiV
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ %{ENV:BASE}index.php [QSA,L]
RewriteCond %{HTTP:Authorization} .+
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
- web.config (IIS配置) http://pastebin.com/1VJf5P3D
- web.config (config for IIS) http://pastebin.com/1VJf5P3D
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="slim" stopProcessing="true">
<match url="^api/v0/(.*)$" ignoreCase="false" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="api/v0/index.php/{R:0}" appendQueryString="true" />
</rule>
</rules>
</rewrite>
<httpErrors existingResponse="PassThrough" />
</system.webServer>
</configuration>
我修改了SlimPHP中提出的原始 .htaccess http://www.slimframework.com/docs/start/web-servers.html 但是我不知道如何更改 web.config 。
I modified the original .htaccess proposed in SlimPHP http://www.slimframework.com/docs/start/web-servers.html but I don't know how to change the web.config.
这是我第一次使用和IIS服务器,我花了一个很多时候研究并试图让它工作没有成功。
This is my first time working with and IIS server and I had spent a lot of time researching and trying to make it work with no success.
推荐答案
此配置文件 web。位于
对我有用:项目/ api / v0 /
中的config
This configuration file web.config
located in Project/api/v0/
is working for me:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="slim" stopProcessing="true">
<match url="^(.*)$" ignoreCase="false" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
</conditions>
<action type="Rewrite" url="index.php/{R:1}" appendQueryString="true" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
这篇关于web.config中的URL重写不适用于子目录中的Slim PHP API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!