简体   繁体   中英

Run WordPress on IIS with ASP.NET site

I am trying to run WordPress in Windows Server 2012 R2 and encountered an issue on displaying other WordPress pages except for the WordPress homepage.

The WordPress files are in ex. wordpress folder.

So the sites are accessible in;
example.com/ – this returns successfully the ASP.NET website
example.com/wordpress – this returns successfully the WordPress homepage website

But when I access different WordPress pages, ex.
example.com/wordpress/about-us – I got an error saying

Server Error in '/' Application.

The resource cannot be found.

Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.
Requested URL: /wordpress/about-us
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.7.2106.0

*Permalink is already setup with this setting
example.com/wordpress/%postname%

*I also tried doing URL Rewrite on IIS Manager but it is not working. On the ASP.NET web.config it shows:

<rule name=”wordpress” enabled=”true” patternSyntax=”ECMAScript” stopProcessing=”true”>
    <match url=”(wordpress/about-us).*” />
    <action type=”Rewrite” url=”index.php” />
    <conditions logicalGrouping=”MatchAny”>
        <add input=”{REQUEST_FILENAME}” matchType=”IsFile” />
        <add input=”{REQUEST_FILENAME}” matchType=”IsDirectory” />
    </conditions>
</rule>

WordPress Version: 5.6
PHP Version: 7.3.24
IIS Version: 8.5

Can someone help me?

WordPress is written in PHP. If you want to run WordPress in a windows machine (eg IIS), you may set Module Mapping in your IIS manager after you have downloaded / installed PHP for windows.

For example, in the IIS Manager's Actions pane, you will be able to choose “Add Module Mapping.” Enter the necessary details to tell IIS that *.php files should be run by php-cgi.exe through FastCGI.

Thank you all so much for responding.

I was creating the Rewrite Rule on the wrong config file. Right now I created it on the “..the same directory where the WordPress files are installed..” as this guide in the link below says.

https://docs.microsoft.com/en-us/iis/extensions/url-rewrite-module/enabling-pretty-permalinks-in-wordpress

For other's reference: web.config file path to create Rewrite Rule: ex. C:\HostingSpaces\ASPWebsite\wordpress\web.config

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
          <rules>
            <rule name="Main Rule" stopProcessing="true">
              <match url=".*" />
              <conditions logicalGrouping="MatchAll">
                <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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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