简体   繁体   English

URL中的IIS php扩展

[英]IIS php extension in URL

I'm migrating an Apache server to an IIS server. 我正在将Apache服务器迁移到IIS服务器。

Currently, in the Apache server , if we have a PHP page named www.example.com/test.php , we can access it even without the final ".php" (ie www.example.com/test ). 当前,在Apache服务器中 ,如果我们有一个名为www.example.com/test.php的PHP页面,即使没有最后的“ .php”(即www.example.com/test ),我们也可以访问它。

How to achieve a similar behavior in IIS? 如何在IIS中实现类似的行为?

With IIS8 and above Microsoft implemented the Web Platforms and you can download the module URL Rewrite from there (or just download it from their site ). 使用IIS8及更高版本,Microsoft实施了Web平台,您可以从此处下载URL Rewrite模块(或直接从其站点下载)。

After that, go to the IIS Service Management and click on "URL Rewrite" 之后,转到IIS服务管理,然后单击“ URL重写”

IIS 8上的URL重写

At the right panel, you'll see a option to "Import rules.." 在右侧窗格中,您将看到“导入规则..”的选项。

将htaccess规则导入IIS

Choose your .htaccess (that you currently have on your public_html ) and click on the "Import" button. 选择您的.htaccess (您当前在public_html ),然后单击“导入”按钮。

This creates a file called web.config in the path of your site with a content that will look like the follwing: 这将在您的网站路径中创建一个名为web.config的文件,其内容类似于以下内容:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="Redirect index.php" stopProcessing="true">
                    <match url="index\.php/(.*)" />
                    <action type="Redirect" url="{R:1}" appendQueryString="false" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>

There are also some online services that may convert your .htaccess to web.config although I've tried a few and the import from the IIS Service Management works better. 还有一些在线服务可能会将您的.htaccess转换为web.config尽管我尝试了一些,但从IIS Service Management导入的效果更好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM