Web.config 将所有路径重定向到 index.php - 不工作 [英] Web.config redirect all paths to index.php - not working
问题描述
我主要使用 Apache 和 .htaccess,但我目前正在处理一个托管在 Windows 服务器上的站点.Web.config 给我带来了很多问题.
I predominantly work with Apache and .htaccess, but I am currently working on a site that is hosted on a Windows server. The Web.config is causing me a lot of problems.
我正在尝试将所有 URL 请求重定向到 index.php,以便 PHP 脚本可以解析 URL 并提供正确的页面.
I am trying to redirect all the URL requests to the index.php so that the PHP script can then parse the URL and serve up the correct page.
.htaccess(在 Apache 上运行良好)如下:
The .htaccess (which works fine on Apache) is as follows:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.*)$ - [NC,L]
RewriteRule ^(.*)$ /index.php [NC,L]
Web.config 重写(不想工作):
The Web.config rewrite (which doesn't want to work):
<rewrite>
<rules>
<rule name="rule 1G" stopProcessing="false">
<match url="^(.*)$" ignoreCase="true" />
<action type="Rewrite" url="/-" />
</rule>
<rule name="rule 2G" stopProcessing="false">
<match url="^(.*)$" ignoreCase="true" />
<action type="Rewrite" url="//index.php" />
</rule>
</rules>
</rewrite>
这是我的 Apache 测试服务器上的站点:http://villasilvana.hotmintmedia.com在实时 Windows 服务器上:http://www.villasilvana.net(更新 - 我不得不将实时站点恢复到原始站点,因为它仍在使用中)
Here is the site on my Apache testing server: http://villasilvana.hotmintmedia.com And here on the live Windows server: http://www.villasilvana.net (UPDATE - I've had to revert the live site back to the original, as it is still in use)
我浏览了 ISS 和 Web.config 上的无数页面,并尝试了许多重写代码的变体,但都没有奏效.我将不胜感激.
I have trawled through countless pages on ISS and Web.config and tried many variations on the rewrite code, none of which have worked. I would appreciate any help.
推荐答案
我知道现在有点晚了,但以防其他人正在寻找
I know it's a bit late in the day, but in case anyone else is looking
<!--web.config url rewrite-->
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Redirect To Index" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="/index.php" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
这篇关于Web.config 将所有路径重定向到 index.php - 不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!