【问题标题】:How to remove .php extension from web.config file from wordpress root folder?如何从 wordpress 根文件夹的 web.config 文件中删除 .php 扩展名?
【发布时间】:2016-04-27 11:19:19
【问题描述】:

我在 WordPress 根文件夹中有静态 PHP 页面。在web.config 文件上,我将默认文件更改为静态PHP 文件home.php。我的网站有一些静态 PHP 页面和一些 WordPress 页面。对于 WordPress 页面,我使用永久链接更改了 SEO 友好 URL,但静态 PHP 页面无法删除 .php 扩展。

像这样:

http://reactore.com/contact-us/ --- WordPress 页面
http://reactore.com/about-us.php --- 静态 PHP 页面

这是我的web.config 文件:

<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

【问题讨论】:

    标签: php html wordpress web content-management-system


    【解决方案1】:

    在您的网络配置中使用此代码:

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

    【讨论】:

    • 如果我添加这个 web.config 文件静态 php 页面工作正常但 wordpress 页面给出错误。
    • 你必须告诉你的网络服务器你正在使用默认页面的 index.php 页面。
    • 我没有使用 index.php 作为默认页面 click here to view my web.config
    • 对于 wordpress 你可以设置这个规则:
    猜你喜欢
    • 2015-01-31
    • 2016-10-27
    • 2023-04-05
    • 2016-04-06
    • 2012-06-23
    • 2017-03-22
    • 2012-06-29
    • 2020-03-25
    • 2013-06-28
    相关资源
    最近更新 更多