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

后端 未结 22 1176
独厮守ぢ
独厮守ぢ 2021-01-29 21:35

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 swea

相关标签:
22条回答
  • 2021-01-29 22:22

    We had the same problem and solved it by checking the error.log of our virtual host. We found the following message:

    AH00670: Options FollowSymLinks and SymLinksIfOwnerMatch are both off, so the RewriteRule directive is also forbidden due to its similar ability to circumvent directory restrictions : /srv/www/htdocs/wp-intranet/

    The solution was to set Options All and AllowOverride All in our virtual host config.

    0 讨论(0)
  • 2021-01-29 22:22

    For nginx users

    Use the following in your conf file for your site (usually /etc/nginx/sites-available/example.com)

    location / { try_files $uri $uri/ /index.php?q=$uri&$args; }

    This hands off all permalink requests to index.php with a URI string and supplied arguments. Do a systemctl reload nginx to see the changes and your non-homepage links should load.

    0 讨论(0)
  • 2021-01-29 22:28

    Before trying to do any permalink or server config changes, please check you .htaccess file. This mostly is a corrupt or blank .htaccess file issue. Reset the htaccess file to the default

    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>
    # END WordPress
    
    0 讨论(0)
  • 2021-01-29 22:32

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

    • 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/.htaccess has 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.html file for details - in Ubuntu, you do it with the helper a2enmod.

    • Verify that apache server is looking at the .htaccess file. 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

    0 讨论(0)
  • 2021-01-29 22:32

    If you have FTP access to your account:

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

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

    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.

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

    0 讨论(0)
  • 2021-01-29 22:34

    Most of the time this issue is fixed by simply visiting the Settings -> Permalink page 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 .htaccess file which magically fixes the issue. The issue often happens after moving a site (the site breaks because the .htaccess gets left behind or the settings need to be updated).

    If WordPress doesn't have the right permissions to write the .htaccess file, 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 .htaccess file yourself or, better, to fix the permissions on that file. The file is at the root of the WordPress installation. cd into 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.

    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 .htaccess files is enabled on the server, as @georgeos already suggested. Note that httpd.conf is not always used (Ubuntu indicates it is deprecated but the official Apache docs still says it is often the main configuration file). /etc/httpd/conf/httpd.conf and /etc/apache2/apache2.conf seem 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 AllowOverride directive is set to All. If it is set to None, your .htaccess file is simply ignored by the server.

    0 讨论(0)
提交回复
热议问题