WordPress page not found after changing permalinks

Permalinks are a critical aspect of a WordPress website’s structure, providing user-friendly URLs that enhance both SEO and user experience. However, occasionally, WordPress users encounter permalink issues that result in ugly or broken URLs. One common solution to this problem involves enabling URL rewriting. In this guide, we will walk you through the process of fixing permalink issues in WordPress by enabling URL rewriting through various methods. WordPress page not found.

Part 1: Enabling Rewrite with a2enmod

The a2enmod command is a utility used to enable or disable Apache modules. By enabling the rewrite module, you can enable URL rewriting for your WordPress website. Follow these steps to get started:

  • Access Your Server: Log in to your server using SSH or another preferred method.
  • Enable the rewrite Module: Run the following command to enable the rewrite module.
sudo a2enmod rewrite

This command activates the module, allowing Apache to rewrite URLs.

  • Restart Apache: After enabling the module, you need to restart Apache for the changes to take effect.
sudo service apache2 restart

Now, your server is ready to process rewritten URLs.

Part 2: Enabling Rewrite in Apache Configuration File

The next step involves configuring Apache to handle URL rewriting for your WordPress website. This is done through the Apache configuration file. Here’s how to do it:

  • Locate the Configuration File: The Apache configuration file is typically located in the /etc/apache2/sites-available/ directory. Look for the .conf file corresponding to your WordPress site.
  • Open the Configuration File: Use your preferred text editor to open the configuration file. You might need superuser privileges, so consider using sudo.
  • Add Rewrite Rules: Inside the <VirtualHost> section for your WordPress site, add the necessary rewrite rules to enable pretty permalinks. We will provide an empty code block where you can insert your rewrite rules.
<VirtualHost *:80>
    ServerName yourdomain.com
    DocumentRoot /var/www/yourdomain.com/public_html

    # Other configuration directives

    # Rewrite rules here
    <Directory "/var/www/yourdomain.com">
                Require all granted
                AllowOverride All

    RewriteEngine on
    RewriteCond %{SERVER_NAME} =yourdomain.com [OR]
    RewriteCond %{SERVER_NAME} =www.yourdomain.com
    RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI}[END,NE,R=permanent]

You will need to reload Apache to enable the new config.

sudo service apache2 reload

Enabling Rewrite in .htaccess File

WordPress uses the .htaccess file to manage URL rewriting within its root directory. You can set up rewrite rules directly in this file. The rewrite rules might already be there, modified by WordPress. If not, follow these steps:

  • Locate .htaccess File: Navigate to your WordPress site’s root directory using your preferred FTP client or file manager. Look for the .htaccess file.
  • Backup Your .htaccess File: Before making any changes, it’s a good idea to create a backup of your existing .htaccess file.
  • Edit the .htaccess File: Open the .htaccess file using a text editor.
  • Insert Rewrite Rules: Within the file, you can place the rewrite rules to enable permalinks.
# BEGIN WordPress

<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]

# END WordPress

Save and Upload: After adding the rewrite rules, save the .htaccess file and upload it back to your server.

WordPress documentation https://wordpress.org/documentation/

Check the other WordPress articles here: https://soltveit.org/category/software/wordpress/

About Author

Related Posts

Your site does not have a default theme

WordPress: Your site does not have a default theme

If you get the message Your site does not have a default theme, it is because you are missing the default theme. The default theme is used…

install php ziparchive

Install PHP ZipArchive for Debian

PHP ZipArchive is a file archive for zip compression used by many web applications and plugins. How to install PHP ZipArchive for Debian is an easy task….

locked out of wordpress

Locked out of WordPress admin panel

If you are locked out of WordPress admin panel, what to do or find out what to do. I will list some of the symptoms and solutions…

Change link color Wordpress

Change link color WordPress

Change link color WordPress. Sometimes your WordPress default link colors don’t fit very well on your page. There isn’t any settings where you can change this in…

fatal error out of memory Wordpress

Fatal error out of memory WordPress

Fatal error out of memory WordPress is caused by, as the message says, out of memory. WordPress itself is not memory hungry. According to WordPress memory requirements,…

wordpress admin blank page after login

WordPress admin blank page after login

WordPress admin blank page after login, the first time is terrifying. Since you found this article, I guess that is what you are experiencing now. If not,…

Leave a Reply