root URL shows "404 - File or directory not found

倾然丶 夕夏残阳落幕 提交于 2019-12-24 20:04:08

问题


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:


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.



来源:https://stackoverflow.com/questions/26182602/root-url-shows-404-file-or-directory-not-found

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!