wordpress permalinks not working - htaccess seems ok but getting 404 error on pages

前端 未结 10 1101
[愿得一人]
[愿得一人] 2020-12-07 19:16

I updated the permalink structure to /%postname%/ and this updated my .htaccess with:

# BEGIN WordPress

RewriteEngine On
Rewri         


        
相关标签:
10条回答
  • 2020-12-07 19:17

    use below .htaccess code, just put your project name (which is in www directory) in below code

    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /project_name/
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /project_name/index.php [L]
    </IfModule>
    
    # END WordPress
    

    Thanks

    0 讨论(0)
  • Yet another possibility: I just updated my macOS which always screws up the Apache config file. Among other things, I also had to re-enable the mod_rewrite module. Find the line that says,

    #LoadModule rewrite_module libexec/apache2/mod_rewrite.so
    

    And remove the hash so it says,

    LoadModule rewrite_module libexec/apache2/mod_rewrite.so
    
    0 讨论(0)
  • 2020-12-07 19:24

    One more thing to check if this describes your problem:

    • htaccess and mod_rewrite are set up correctly
    • 404 error on some permalinks but not others

    Ensure that there are no existing .php files or directories in the same folder as your Wordpress install with names matching a Wordpress permalink.

    For example, if you have the following Wordpress page permalinks:

     example.com/name_one/
     example.com/name_two/
    

    and the directory containing your Wordpress install includes the following file:

     name_one.php
    

    then this will be the result:

    • http://example.com/name_two/ – this permalink will work
    • http://example.com/name_one/ – this permalink will NOT work

    More importantly, the second URL will give a 404 instead of running name_one.php, meaning this problem is hard to diagnose, as it can give the same symptoms as an incorrectly written .htaccess file.

    0 讨论(0)
  • 2020-12-07 19:29

    You would want to tell apache to follow your .htaccess file. You can do this by editing the apache.conf file

    $sudo nano /etc/apache2/apache.conf
    

    Scroll down to the line By default it will be:

    <Directory /var/www/>
    Options Indexes FollowSymLinks
    AllowOverride None
    Require all granted
    </Directory>
    

    change the value of AllowOverride to All so now it becomes:

    <Directory /var/www/>
    Options Indexes FollowSymLinks
    AllowOverride All
    Require all granted
    </Directory>
    

    Press ctrl+x and press y to save the configuration file. In order to make this changes to server first enable the mod_rewrite by.

    $ sudo a2enmod rewrite
    

    And then restart the server

    $ sudo service apache2 restart
    

    Done!

    Source: https://www.wst.space/riddling-with-wordpress-permalink-setup-issues/

    0 讨论(0)
  • 2020-12-07 19:31

    This is now solved. I hadn't enabled mod_rewrite. So I did this:

    $ sudo a2enmod rewrite
    Enabling module rewrite.
    To activate the new configuration, you need to run:
      service apache2 restart
    $ service apache2 restart
     * Restarting web server apache2                                                                              
    
    0 讨论(0)
  • 2020-12-07 19:31

    If you are setting up a new or cloned site on ubuntu, remember to symlink the site configuration file e.g. /etc/apache2/sites-available/your-file.conf to the /etc/apache2/sites-enabled folder so apache loads it.


    Just run: sudo a2ensite your-file.conf, then sudo service apache2 reload.

    sudo a2dissite your-file.conf to remove symlink i.e. disable config.

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