Original Question
Problem Statement:
I am trying to change the URLs for my WordPress posts to use “post names” instead of “page numbers” by modifying the permalink structure. However, after making the change, my posts and the post page are not showing.
Troubleshooting Steps
1. Change the Permalink Structure in WordPress
- Navigate to the WordPress dashboard.
- Go to Settings > Permalinks.
- Select the Post name option and save the changes. If posts are not displayed after this change, proceed with the steps below.
2. Verify .htaccess
File Configuration
Ensure the .htaccess file exists in the root of the WordPress installation (e.g., /var/www/html/.htaccess).
Check that the file contains the correct WordPress rewrite rules:
# BEGIN WordPress
# The directives (lines) between "BEGIN WordPress" and "END WordPress" are
# dynamically generated, and should only be modified via WordPress filters.
# Any changes to the directives between these markers will be overwritten.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Options All -Indexes
3. Enable the mod_rewrite
Module
- On Rocky Linux, verify that the
mod_rewrite
module is loaded:bash grep "rewrite_module" /etc/httpd/conf.modules.d/00-base.conf
- If the module is not listed, ensure it is enabled in
/etc/httpd/conf.modules.d/00-base.conf
:plaintext LoadModule rewrite_module modules/mod_rewrite.so
- Restart Apache to apply changes:
bash sudo systemctl restart httpd
4. Check Apache Directory Configuration
- Open the Apache configuration file:
bash sudo nano /etc/httpd/conf/httpd.conf
- Locate the
<Directory>
block for your WordPress root directory. By default, it might look like this:plaintext <Directory "/var/www/html"> AllowOverride None Require all granted </Directory>
- Modify it to allow
.htaccess
files to override settings:plaintext <Directory "/var/www/html"> AllowOverride All Require all granted </Directory>
- Save and exit the file.
5. Restart Apache
Restart Apache to apply the configuration changes:
sudo systemctl restart httpd
6. Flush WordPress Rewrite Rules
- Go to Settings > Permalinks in the WordPress dashboard.
- Click Save Changes without making any changes to regenerate the rewrite rules.
7. Verify SELinux Settings (If Enabled)
If SELinux is in enforcing mode, it might block .htaccess
from being used:
- Temporarily set SELinux to allow HTTPD scripts:
bash sudo setsebool -P httpd_unified 1
- Alternatively, check SELinux logs for specific errors and create custom policies as needed.
8. Check Apache Logs
- Review Apache logs for errors related to
.htaccess
or rewrite rules:bash sudo tail -f /var/log/httpd/error_log
Final Fix
After reviewing the configurations and following the troubleshooting steps, the issue was resolved by modifying the <Directory>
block in the Apache configuration file.
Original Configuration:
<Directory "/var/www/html">
AllowOverride None
Require all granted
</Directory>
Updated Configuration:
<Directory "/var/www/html">
AllowOverride All
Require all granted
</Directory>
This change allowed .htaccess
files to override the server’s default configuration, enabling WordPress’s rewrite rules for pretty permalinks.
Summary
To resolve WordPress permalink issues on Rocky Linux:
- Ensure
.htaccess
contains the correct rewrite rules. - Confirm
mod_rewrite
is enabled and loaded. - Update the
<Directory>
block in the Apache configuration to allow.htaccess
overrides (AllowOverride All
). - Restart Apache and flush WordPress rewrite rules.
- Check SELinux and logs for additional issues if necessary.
0 Comments