Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
删除IIS7上带有web.config的.php扩展_Php_.htaccess_Url Rewriting_Web Config - Fatal编程技术网

删除IIS7上带有web.config的.php扩展

删除IIS7上带有web.config的.php扩展,php,.htaccess,url-rewriting,web-config,Php,.htaccess,Url Rewriting,Web Config,我有一个.htaccess文件,该文件从文件中删除.php扩展名,例如将so.com/question.php转换为so.com/question,并重定向文件夹中的索引文件,例如,so.com/answer/index.php重定向到so.com/answer/,完全如前所述 我刚刚在IIS7上本地设置了我的站点,需要在web.config中重新创建相同的行为,但不知道从哪里开始转换/重写.htaccess文件。我发现IIS7及以上版本可以使用URL重写模块导入Apache.htaccess规

我有一个.htaccess文件,该文件从文件中删除.php扩展名,例如将so.com/question.php转换为so.com/question,并重定向文件夹中的索引文件,例如,so.com/answer/index.php重定向到so.com/answer/,完全如前所述


我刚刚在IIS7上本地设置了我的站点,需要在web.config中重新创建相同的行为,但不知道从哪里开始转换/重写.htaccess文件。

我发现IIS7及以上版本可以使用URL重写模块导入Apache.htaccess规则

  • 通过Microsoft Web平台安装程序安装
  • 启动IIS管理器,在左侧的“连接”窗格中,选择所需的站点(例如,默认网站)
  • 在中心(功能视图)双击URL重写
  • 在右侧面板中,单击导入规则…,然后将规则从.htaccess文件粘贴到重写规则框中
  • 单击右侧列中的应用
  • 在上面的特定问题中,使用以下.htaccess重定向规则

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME}.php -f
    RewriteRule ^(.*)$ $1.php [NC,L]
    
    生成以下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>