Today I was working on a client’s WordPress site who needed permalinks enabled so that the post name would show up in the address bar which is much better for SEO purposes. I enabled permalinks with the post name option in the admin of WordPress, but got page not found errors when visiting the posts, so I had to find the solution. Here is what I did.
I read online that mod_rewrite was probably the culprit. Before assuming this, you should make sure your .htaccess file is working properly and is writable from WordPress before setting permalinks up. You can simply make sure the file exists and set permissions to 777, enable permalinks, then set your permissions back as they were to make your file secure once again. If that doesn’t do it, then check your mod_rewrite using the following procedure:
- make a info.php file with only this for content: “<?php phpinfo(); ?>” and save it as info.php. Upload to your root directory and go to your domain name/info.php and search for the text “mod_rewrite” if you find it in the php info file, then your mod_rewrite is enabled. If not, then enable it.
- To enable mod_rewrite, try the command line command: sudo a2enmod rewrite
If mod_rewite was enabled then something else is wrong. Check your etc/httpd/conf/httpd.conf file. It should have the following in it:
Basically, you’ll be adding All insted of None to AllowOverride, you do not want to edit the main directory configuration, you want to edit the one that looks like this:
Then restart Apache with:
sudo service httpd restart
from the command line.
Now, if you are using WordPress and trying to enable Permalinks as I was, next, go to your wp-admin page and go to settings/permalinks and change from default to post-name and click the save button to save the changes and try again. If you did this before making mod_rewrite fixes, you may need to change back to default, save, and then change to post-name again and save one last time for the settings to work.