babbaggeii
babbaggeii

Reputation: 7737

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

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

# 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

But I still get 404 errors on the pages. Are there any other settings that I need to change?

Edit: if it helps the apache log seems to be looking directly in the permalinked folder. I.e.:

[Wed Oct 16 11:12:32 2013] [error] [client xx.xx.xx.xxx] File does not exist: /var/www/exampledomain/news, referer: http://exampledomain.com/

Upvotes: 42

Views: 65747

Answers (11)

If you are using Apache, double check no errors in Directory in VirtualHost, Apache wont warn you if you input an incorrect directory:

<Directory /var/www/html/site/wordpress>
  Options FollowSymLinks
  AllowOverride Limit Options FileInfo
  DirectoryIndex index.php
  Require all granted
</Directory>
<Directory /var/www/html/site/wordpress/wp-content>
  Options FollowSymLinks
  Require all granted
</Directory>

Upvotes: 0

Rick Gladwin
Rick Gladwin

Reputation: 4905

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:

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.

Upvotes: 1

Anonymous Platypus
Anonymous Platypus

Reputation: 1302

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/

Upvotes: 14

Jeff
Jeff

Reputation: 14279

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

Upvotes: 0

khurram
khurram

Reputation: 946

Users of WAMP (Windows): Some versions of WAMP (all versions?) do not enable mod_rewrite or permit following SymLinks by default. To enable the required functionality navigate to the apache/conf/httpd.conf file, open with a text editor and uncomment the line LoadModule rewrite_module modules/mod_rewrite.so (i.e., delete the hash/pound sign at the front of the line). Then further down in the same file there is a section that starts with the line "Options FollowSymlinks". Change the second line in that section from "AllowOverride none" to AllowOverride all. Save edited httpd.conf and restart all WAMP modules. Your permalinks should now work.

For more details, Fixing Permalink Problems

Upvotes: 0

MTLHD777
MTLHD777

Reputation: 853

For other people landing on this page - Another issue could be (If you are using Apache as your web server) is your httpd.conf or your sites-available/sitename.conf file needs editing.

Your web directory will need to allow the .htaccess file to override it's settings.

look for your web dir in the file - it will be in the bulk of the conf file or segregated into a VirtualHost section.

<Directory /path/to/site>
     #add the following setting to allow .htaccess in your web dir to work
     AllowOverride FileInfo

     #other settings ---

</Directory>

This will allow you to set up WordPress URLs however you want, within WordPress.

***Edited - Thank You nietonfir For update. Use the least amount of privilege at first. If this doesn't work then replace AllowOverride FileInfo with AllowOverride All

Upvotes: 85

ganchclub
ganchclub

Reputation: 29

I was facing with the same problem and had one more thing to look for.

Here is what you need to do for wordpress permalinks work properly:

  1. Make sure you have the proper permission modes for files and folders in your wordpress directory:
    sudo find . -type f -exec chmod 644 {} +
    sudo find . -type d -exec chmod 755 {} +

  2. For permalink structure make sure mode_rewrite is enabled in apache:
    sudo a2enmod rewrite
    sudo service apache2 restart

Upvotes: 1

Natalie
Natalie

Reputation: 351

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.

Upvotes: 0

gan
gan

Reputation: 3099

There can be multiple things preventing the rewrite rule from working. My ubuntu server needed 3 things changed to get permalinks working.

In newer versions of apache2, you need to enable the module:

sudo a2enmod rewrite
sudo service apache2 restart

You may also need to modify the apache2.conf file.

sudo nano /etc/apache2/apache2.conf

Change your web directory override rule to AllowOverride All.

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

After that, restart the service again.

The .htaccess file in the WordPress install directory needs to be owned or readable/modifiable by the webserver.

This can be accomplished by changing owner to www-data (usually the webserver user), or changing permissions.

sudo chown www-data /var/www/wordpress-install/.htaccess 

OR

sudo chmod 664 /var/www/wordpress-install/.htaccess

Login to your Wordpress admin backend and save the permalink settings, and they should hopefully be working.

Upvotes: 61

Krunal Shah
Krunal Shah

Reputation: 2101

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

Upvotes: 6

babbaggeii
babbaggeii

Reputation: 7737

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                                                                              

Upvotes: 32

Related Questions