How to fix WordPress permalink problem with mod_rewrite?

How to fix WordPress permalink problem with mod_rewrite?

This tutorial explains how to fix WordPress permalink problem, which occurs due to incomplete Apache2 webserver configuration.

When you try to change the Permalink structure in your WordPress -> Settings -> Permalinks your posts, pages and menu links become unreachable.

This happens because AllowOverride directive in your webserver configuration file is set to None and does not allow the .htaccess file to rewrite your website URLs.

Editing the AllowOverride directive in your webserver configuration file /etc/httpd/conf/httpd.conf (CentOS) / /etc/apache2/apache2.conf (Ubuntu) will help you resolve this problem.

 

Prerequisites:

 

Summary:
  1. Configure Apache2
  2. Restart Apache2
  3. Configure WordPress

 

1. Configure Apache2

1.1. Firstly, you will need to edit the webserver configuration file.

Command: nano /etc/httpd/conf/httpd.conf

1.2. Then, find the directive AllowOverride None in your website directory part of configuration <Directory "/var/www/html"> as in the sample output bellow. Change the AllowOverride None directive to AllowOverride All. After that you can save and exit out of the file.

Output:


<Directory “/var/www/html”>

#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be “All”, “None”, or any combination of the keywords:
# Options FileInfo AuthConfig Limit
#
AllowOverride None

</Directory>

2. Restart Apache2

You need to restart your Apache2 webserver for changes to take affect.

Command: systemctl restart httpd.service

3. Configure WordPress

Finally, you need to configure the permalinks in your WordPress -> Settings -> Permalinks. Choose the permalink option that is most suitable for you and then save the changes. Then load your WordPress website in your browser and open a post, page or menu link. The posts, pages and links are now loading normally and with the permalink structure, which you have selected.

 

Conclusion

You have changed the settings in your webserver configuration file, then rebooted your webserver. This allows mod_rewrite module to rewrite your WordPress website URLs according to the rules in your .htaccess file.

 

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.