删除的.php扩展名与web.config中IIS7上 [英] Remove .php extensions with web.config on IIS7
问题描述
我有一个的.htaccess 文件,该文件中删除PHP扩展的文件,将例如 so.com/question.php 的到的 so.com/问题的,并且也重新定向索引文件的文件夹中,如 so.com/answer/index.php 的重定向到的 so.com/answer / 的确切描述的这个答案
I have an .htaccess file which removes the .php extension from files, converting for example so.com/question.php to so.com/question, and also redirecting the index file in the folder, e.g. so.com/answer/index.php redirects to so.com/answer/ exactly as described in this answer
我刚刚建立了我的网站在本地IIS7和需要重新创建一个 web.config中相同的行为,但不知道从哪里开始转换/重写.htaccess文件。
I have just set up my site locally on IIS7 and need to recreate the same behaviour in a web.config but don't know where to start with converting/rewriting the .htaccess file.
推荐答案
我发现IIS7及以上的可以使用的 URL重写模块导入的Apache的.htaccess规则
I have found that IIS7 and above can import Apache .htaccess rules using the URL Rewrite module.
- 安装通过的 Microsoft Web平台的 URL重写模块安装的
- 启动IIS管理器,并在左侧,在连接窗格中,选择您所需的网站(如默认网站)
- 在中心(功能视图)双击 URL重写
- 在右侧面板中点击导入规则... ,然后粘贴在.htaccess文件的规则到重写规则箱
- 单击应用在右列。
- Install the URL Rewrite module via the Microsoft Web Platform Installer
- Start IIS Manager and on the left, in the Connections pane, select your required site (e.g. Default Web Site)
- In the centre (Features View) double click URL Rewrite.
- In the right panel click Import Rules... then paste your rules from the .htaccess file into the Rewrite rules box
- Click apply in the right column.
在上面下面的.htaccess中的具体问题,重定向规则
In the specific question above the following .htaccess redirect rules
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php [NC,L]
生成以下web.config文件。
generate the following web.config file.
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Imported Rule 1" stopProcessing="true">
<match url="^(.*)$" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
<add input="{REQUEST_FILENAME}.php" matchType="IsFile" ignoreCase="false" />
</conditions>
<action type="Rewrite" url="{R:1}.php" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
这篇关于删除的.php扩展名与web.config中IIS7上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!