root URL shows "404 - File or directory not found

2019-08-31 00:16发布

The root URL of my blog shows "404 - File or directory not found.". It happened immediately after I changed by permalink settings and applied "day and name".

If I change my permalink settings to Default then everything works fine.

It works perfectly when I use MyDomain.com/page however when I just try MyDomain.com/page it throws 404 error.

Following link tells me a solution but it is not possible for me as I have my site on shared hosting. It is on IIS 7.

Any help would be appreciated.

Thanks

1条回答
来,给爷笑一个
2楼-- · 2019-08-31 00:56

Basically, for the permalink to work, you need to rewrite requests to index.php, so the right parameters can be parsed and sent downwards. Therefore, different web server should include different rewrite rules.

For instance, for nginx servers, you need to set the following rewrite rules to the wordpress root

try_files $uri $uri/ /index.php?q=$request_uri;

I'm not very family with IIS, but according to http://www.iis.net/learn/extensions/url-rewrite-module/enabling-pretty-permalinks-in-wordpress, you should be able to enable permalink by adding:

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

to system.webServer section.

I know the nginx setting works because I'm using it myself. You can try the IIS rule on your own server.

查看更多
登录 后发表回答