简体   繁体   中英

How to remove .php extension from web.config file from wordpress root folder?

I have static PHP pages in the WordPress root folder. On the web.config file, I changed the default file to static PHP file home.php . I am having a few static PHP pages and a few WordPress pages for my website. For WordPress pages, I changed SEO friendly URL using permalinks, but static PHP pages not able to remove .php extensions.

Like this:

http://reactore.com/contact-us/ --- WordPress page
http://reactore.com/about-us.php --- static PHP page

This is my web.config file:

<rewrite>
    <rules>
        <rule name="WPurls" enabled="true" 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/{R:0}" />
        </rule>
    </rules>
</rewrite>

Click to view my web.config file at JSFiddle

Use this code in your web config:

<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>

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