ajc*_*jcw 6 php .htaccess web-config url-rewriting
我有一个htaccess的文件,该文件从文件中删除的PHP扩展,变换为例如so.com/question.php到so.com/question,并且还在文件夹中重定向索引文件中,例如so.com/answer/index .php完全按照本答案中的描述重定向到so.com/answer/
我刚刚在IIS7上本地设置了我的站点,需要在web.config中重新创建相同的行为,但不知道从哪里开始转换/重写.htaccess文件.
ajc*_*jcw 26
我发现IIS7及以上版本可以使用URL Rewrite模块导入Apache .htaccess规则.
在上面的具体问题中,以下.htaccess重定向规则
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php [NC,L]
Run Code Online (Sandbox Code Playgroud)
生成以下web.config文件.
<?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>
Run Code Online (Sandbox Code Playgroud)