WordPress 给了我 404 页面,除主页之外的所有页面都找不到

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5182534/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 18:43:57  来源:igfitidea点击:

WordPress is giving me 404 page not found for all pages except the homepage

wordpress

提问by Adam

All of a sudden I go to my WordPress website and all the pages give me a 404 page not found page. I'm assuming the problem lies with the permalink structure, which I could swear I did not touch. The permalink setting is on "month and name."

突然间,我转到我的 WordPress 网站,所有页面都给我一个 404 页面未找到页面。我假设问题出在永久链接结构上,我可以发誓我没有碰过它。永久链接设置为“月份和名称”。

I've researched similar instances of this problem online and a lot of it has to do with the .htaccessfile? I tried finding, but I can't. Perhaps it got deleted somehow? Where is it supposed to be located.

我在网上研究了这个问题的类似实例,其中很多都与.htaccess文件有关?我试图找到,但我不能。也许它以某种方式被删除了?它应该位于哪里。

Any suggestions will be helpful

任何建议都会有所帮助

and of course I can see hidden files.

当然我可以看到隐藏文件。

采纳答案by Rochester Oliveira

.htaccess is a hidden file, so you must set all files as visible in your ftp.

.htaccess 是一个隐藏文件,因此您必须将所有文件设置为在您的 ftp 中可见。

I suggest you return your permalink structure to default ( ?p=ID ) so you ensure that .htaccess is the problem.

我建议您将永久链接结构恢复为默认值( ?p=ID ),以便确保 .htaccess 是问题所在。

After that, you could simply set "month and name" structure again, and see if it works.

之后,您可以简单地再次设置“月份和名称”结构,看看它是否有效。

PS: Have you upgraded to 3.1? I've seen some people with plugin issues in this case.

PS:你升级到3.1了吗?在这种情况下,我见过一些人有插件问题。

回答by georgeos

Basically the .htaccess file should exists and the httpd.conf should be correct.

基本上 .htaccess 文件应该存在并且 httpd.conf 应该是正确的。

In my case, I changed the file /etc/apache2/apache2.conf in section:

就我而言,我在部分更改了文件 /etc/apache2/apache2.conf:

<Directory "/var/www/html">

Line changed is:

更改的行是:

AllowOverride None

to

AllowOverride All

And restart the web server with

并使用以下命令重新启动 Web 服务器

systemctl restart apache2

回答by usama sulaiman

Fixing that problem is very simple if you was using permalinks other than the defaultsuch as Day and name, Month and name, Numeric, Post nameor Custom Structure, you only need to

如果您使用的defaultDay and name, Month and name, Numeric,Post name或以外的永久链接,则解决该问题非常简单Custom Structure,您只需要

Login to your admin area: Settings > Permalinkswhich should be : http://yoursite.com/wp-admin/options-permalink.php

登录到您的管理区域:Settings > Permalinks应该是:http://yoursite.com/wp-admin/options-permalink.php

Choose Defaultpermalink setting, then save changes

选择Default永久链接设置,然后保存更改

Then you can return it again to your other previous permalink choiceor keep it as defaultas yo wish

然后您可以再次将其返回到您之前的其他永久链接选择按照您的意愿保留它default

Note that this problem can happen when you move your site from a domain or location to another one.

请注意,当您将站点从一个域或位置移动到另一个域或位置时,可能会发生此问题。

回答by tsvikas

If the default behavior (example.com/?p=42) is working, you should:

如果默认行为 ( example.com/?p=42) 有效,您应该:

  • Change to your preferred permalink style: Admin: Settings > Permalinks, and click Save. Sometime it fixes the issue. If it didn't:
  • Verify that the file /path/to/wordpress/.htaccesshas been changed and now includes the line RewriteEngine On. If it doesn't include the line, it's a Wordpress permissions issue.
  • Verify that the 'rewrite' module is loaded: create a PHP file with

    <?php
      phpinfo()
    ?>
    

    in it, open it in the browser and search for mod_rewrite. It should be in the 'Loaded Modules' section. If it's not, enable it - Look at your apache default index.htmlfile for details - in Ubuntu, you do it with the helper a2enmod.

  • Verify that apache server is looking at the .htaccessfile. open httpd.conf- or it's Ubuntu's alternative, /etc/apache2/apache2.conf. In it, You should have something like

    <Directory /path/to/wordpress>
      Options Indexes FollowSymLinks
      AllowOverride All
      Require all granted
    </Directory>
    
  • After making these changes, don't forget to restart your apache server. sudo service apache2 restart

  • 更改为您首选的永久链接样式:Admin: Settings > Permalinks,然后单击保存。有时它可以解决问题。如果没有:
  • 验证文件/path/to/wordpress/.htaccess是否已更改并且现在包含行RewriteEngine On. 如果它不包含该行,则是 Wordpress 权限问题。
  • 验证“重写”模块是否已加载:创建一个 PHP 文件

    <?php
      phpinfo()
    ?>
    

    在其中,在浏览器中打开它并搜索mod_rewrite. 它应该在“加载的模块”部分。如果不是,请启用它 - 查看您的 apache 默认index.html文件以了解详细信息 - 在 Ubuntu 中,您可以使用 helper 来完成a2enmod

  • 验证 apache 服务器是否正在查看该.htaccess文件。打开httpd.conf- 或者它是 Ubuntu 的替代方案,/etc/apache2/apache2.conf. 在里面,你应该有类似的东西

    <Directory /path/to/wordpress>
      Options Indexes FollowSymLinks
      AllowOverride All
      Require all granted
    </Directory>
    
  • 进行这些更改后,不要忘记重新启动 apache 服务器。 sudo service apache2 restart

回答by David Valenza

IF all this dont work, your .htaccess is correct, and permalinks trick didnt work, you may have not enabled your apache2 rewite mod.

如果所有这些都不起作用,您的 .htaccess 是正确的,并且永久链接技巧不起作用,您可能没有启用您的 apache2 rewite mod

I ran this and my issue was solved:

我运行了这个,我的问题解决了:

 sudo a2enmod rewrite 

回答by Mahesh singh chouhan

Within the WordPress admin interface do the following:

在 WordPress 管理界面中执行以下操作:

  1. Go to admin setting

  2. Click on permalink and select post name in radio button.

  3. Scroll down and you will see .htaccesscode here like.

    <IfModule mod_rewrite.c>
        RewriteRule ^index\.php$ - [L]
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteRule . /wordpress/index.php [L]
    </IfModule> 
    
  4. Copy the code and paste in the .htaccessfile.
  1. 进入管理设置

  2. 单击永久链接并在单选按钮中选择帖子名称。

  3. 向下滚动,您将.htaccess在此处看到类似的代码。

    <IfModule mod_rewrite.c>
        RewriteRule ^index\.php$ - [L]
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteRule . /wordpress/index.php [L]
    </IfModule> 
    
  4. 复制代码并粘贴到.htaccess文件中。

回答by Asif Khan

This error is causing due to disabled of rewrite mod in apache httpd.conf document ,just uncomment it and enjoy the seo friendly permalinks

此错误是由于禁用了 apache httpd.conf 文档中的重写 mod 引起的,只需取消注释即可享受 seo 友好的永久链接

回答by José Carlos

  • Check that the directory on .htaccess are the correct
  • Check the fields "siteurl" and "home" are the correct
  • 检查 .htaccess 上的目录是否正确
  • 检查字段“siteurl”和“home”是否正确

回答by JEFF B

If you have FTP access to your account:

如果您可以通过 FTP 访问您的帐户:

First, login to your wp-admin and go to Settings > Permalinks

首先,登录您的 wp-admin 并转到“设置”>“永久链接”

You should see something at the bottom that says:

您应该会在底部看到以下内容:

"If your .htaccess file were writable, we could do this automatically, but it isn't so these are the mod_rewrite rules you should have in your .htaccess file. Click in the field and press CTRL + a to select all."

“如果您的 .htaccess 文件是可写的,我们可以自动执行此操作,但事实并非如此,这些是您应该在 .htaccess 文件中拥有的 mod_rewrite 规则。单击该字段并按 CTRL + a 选择全部。”

If this is true do the following:

如果这是真的,请执行以下操作:

  1. Go into preferences for your FTP client and make sure hidden files are displayed (varies depending on your FTP client) - If you don't do this you won't be able to find your htaccess file

  2. Go to the folder that your wp-admin, wp-content, wp-includes directories are located. Check for .htaccess file. If it exists skip to step 4

  3. If it does not exist, create a new blank file in your FTP program called .htaccess

  4. Change the CHMOD for your .htaccess file to 666 (your preference on how you want to do this)

  5. Go back to your Permalinks page and edit the link structure you want. Problem should be solved!

  6. Make sure to change the chmod of the htaccess file back to 644 after you are done.

  1. 进入您的 FTP 客户端的首选项并确保显示隐藏文件(因您的 FTP 客户端而异) - 如果您不这样做,您将无法找到您的 htaccess 文件

  2. 转到 wp-admin、wp-content、wp-includes 目录所在的文件夹。检查 .htaccess 文件。如果存在跳到第4步

  3. 如果它不存在,请在您的 FTP 程序中创建一个名为 .htaccess 的新空白文件

  4. 将 .htaccess 文件的 CHMOD 更改为 666(您对如何执行此操作的偏好)

  5. 返回您的永久链接页面并编辑您想要的链接结构。问题应该解决!

  6. 确保在完成后将 htaccess 文件的 chmod 更改回 644。

Just had the same problem and it seemed to fix it instantly! Good luck!

刚刚遇到了同样的问题,它似乎立即解决了!祝你好运!

回答by mrtnmgs

Most of the time this issue is fixed by simply visiting the Settings -> Permalinkpage in the WordPress admin and click Save (as several other answers already pointed out). When this page is accessed, WordPress rewrites the directives in the .htaccessfile which magically fixes the issue. The issue often happens after moving a site (the site breaks because the .htaccessgets left behind or the settings need to be updated).

大多数情况下,只需访问WordPress 管理员中的“设置”->“永久链接”页面并单击“保存即可解决此问题(正如其他几个答案已经指出的那样)。当访问此页面时,WordPress 会重写.htaccess文件中的指令,从而神奇地解决了该问题。该问题通常在移动站点后发生(站点因.htaccess遗留问题或需要更新设置而中断)。

If WordPress doesn't have the right permissions to write the .htaccessfile, a notice will appear at the top of the page and further instructions at the bottom when the settings are saved. In this case you need to edit the .htaccessfile yourself or, better, to fix the permissions on that file. The file is at the root of the WordPress installation. cdinto the directory and sudo chmod 644 .htaccess. You might also want to check if the file belongs to the right group and change that is needed with chown. Ask your hosting provider if you don't know how to do that.

如果 WordPress 没有写入.htaccess文件的正确权限,则在保存设置时,页面顶部会显示一条通知,底部会显示更多说明。在这种情况下,您需要自己编辑.htaccess文件,或者更好地修复该文件的权限。该文件位于 WordPress 安装的根目录下。cd进入目录和sudo chmod 644 .htaccess. 您可能还想检查文件是否属于正确的组并使用chown. 如果您不知道如何操作,请咨询您的托管服务提供商。

If you are on shared hosting that's probably all you can do. If you still have the issue you might want to talk to you hosting provider's support. Otherwise, make sure the use of .htaccessfiles is enabled on the server, as @georgeos already suggested. Note that httpd.confis not always used (Ubuntu indicates it is deprecatedbut the official Apache docs still says it is often the main configuration file). /etc/httpd/conf/httpd.confand /etc/apache2/apache2.confseem to be the most common places for this file. Find the block for the public folder, usually <Directory /var/www/>and make sure that the AllowOverridedirective is set to All. If it is set to None, your .htaccessfile is simply ignored by the server.

如果您使用共享主机,这可能就是您所能做的。如果您仍然遇到问题,您可能需要与托管服务提供商的支持人员联系。否则,请确保在.htaccess服务器上启用文件的使用,正如@georgeos 已经建议的那样。请注意,httpd.conf它并不总是使用(Ubuntu 表示它已被弃用,官方 Apache 文档仍然表示它通常是主要配置文件)。/etc/httpd/conf/httpd.conf并且/etc/apache2/apache2.conf似乎是这个文件最常见的地方。找到公共文件夹的块,通常<Directory /var/www/>并确保AllowOverride指令设置为All. 如果设置为None.htaccess则服务器将忽略您的文件。