Skip to content
NYC Tech Tips

NYC Tech Tips

Tech Tips From a NYC System Administrator

  • Home
  • About
  • Downloads
  • JB Network Design
  • Toggle search form

WordPress Permalinks Causing 404 Error

Posted on April 14, 2020April 17, 2020 By ninjatechnyc

This blog is a selfhosted WordPress instance. When I initially set it up, I had used the default settings of the permalinks section:


WordPress Permalinks Settings
 

After some time, I wanted the post urls to refer to the post title, so I selected “Post name” instead. That’s when all heck broke loose.

 

When clicking on a post from the main page, I kept getting the dreaded 404 error initially:

 
 

This is where I went down my rabbit hole. As usual, I googled for solutions, and the first thing I found told me to open up the apache2.conf and make sure the AllowOverride All was set. Interestingly, I did not even have an entry of nyctechtips.com, so I added:

 

<Directory /var/www/nyctechtips.com>
Options Indexes FollowSymlinks
AllowOverride All
Require all granted
</Directory>

 

I restarted apache after this, but no change. Found another post that said I had to make sure mod-rewrite was enabled. So I tried:

 

sudo a2enmod rewrite

 

but got command not found. Now I know this is an Ubuntu command, and I’m running Ubuntu 18.4, so it should be there. The post then gave another method to enable it, by manually moving the module files:

 

sudo mv /etc/apache2/mods-available/rewrite.load /etc/apache2/mods-enabled/

 

After another apache restart, no change with my permalinks.

 

I noticed the mods-enabled folder all had symlinks and not actual files. So I deleted the rewrite.load file from that folder and instead created the symbolic link:

 

sudo ln -s /etc/apach2/mods-available/rewrite.load /etc/apache2/mods-enabled/rewrite.load

 

Here, I inadvertently left out the “e” in apache. But it created the wrong link anyway (dug my rabbit hole deeper).

 

So when I tried to restart apache now, I got:

 

Job for apache2.service failed because the control process exited with error code.
See “systemctl status apache2.service” and “journalctl -xe” for details.

 

Now I tried the sudo a2enmode rewrite again, and this time it worked, giving the following message:

 

Removing dangling link /etc/apache2/mods-enabled/rewrite.load
Enabling module rewrite.
To activate the new configuration, you need to run:
systemctl restart apache2

 

Still nothing after another apache restart.

 

Next thing was the .htaccess file that was located in the same folder as my wp-config.php file. It should have:

 
# 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
 

Added the above, restarted apache, now I’m getting 403 Forbidden errors and can’t get to the main page!

 

This actually was progress. Checking the /var/log/apache2/error_log, I found the following error:

 

[Tue Apr 14 09:02:31.080955 2020] [rewrite:error] [pid 5361] [client x.x.x.x:64097] AH00670: Options FollowSymLinks and SymLinksIfOwnerMatch are both off, so the RewriteRule directive is also forbidden due to its similar ability to circumvent directory restrictions : /var/www/nyctechtips.com/wp-admin/options-permalink.php, referer: http://nyctechtips.com/wp-admin/options-permalink.php

 

Doing another google search I found that I had to add “Options +FollowSymLinks” to the start of my .htaccess file.

 
Options +FollowSymLinks
# 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
 

Restarted apache one last time and viola!! Working permalinks and webpage!! So ultimately, I think if you’re running your own hosted WordPress instance on Apache/Ubuntu and you’re trying to get the permalinks to work, make sure of the following:

 

  • Make sure you have the AllowOverride All entry in the apache2.conf file under the <Directory> section for your domain
  • Make sure you have mod-rewrite  enabled (sudo a2enmod rewrite)
  • Make sure you have the .htaccess file in the WordPress root folder (with 0644 permissions for the file 0755 for the folder; also make sure it has the “.” at the beginning of the filename)
  •  
  • Make sure the .htaccess file has the Options +FollowSymLinks entry on top
  • Restart Apache
  • Set the permlinks to Post name in the WordPress Settings
 

Hopefully this helps someone else who falls down the same rabbit hole.

linux, tech, tech tips Tags:403 Error, apache, htaccess, permalinks, ubuntu, Wordpress

Post navigation

Previous Post: Koken – API Error. The theme is not able to make contact with your Koken installation.
Next Post: WordPress Post Editor Gutenberg

Search

Tags

adobe Amazon antispyware antivirus apache Apple AT&T blackberry browser China computer data breach Dell dilbert dogbert email encryption facebook faulting application FB firefox firewall flash drives freeware godaddy google Hack Identity Theft Internet Explorer iPhone linux malware Microsoft paypal phishing privacy recommended reading scam security software tech support ubuntu virus windows Wordpress

Archives

  • April 2021
  • September 2020
  • July 2020
  • June 2020
  • May 2020
  • April 2020
  • June 2017
  • May 2017
  • December 2016
  • November 2015
  • June 2015
  • June 2012
  • February 2012
  • January 2012
  • December 2011
  • November 2011
  • September 2011
  • July 2011
  • May 2011
  • April 2011
  • March 2011
  • January 2011
  • December 2010
  • October 2010
  • August 2010
  • June 2010
  • May 2010
  • April 2010
  • March 2010
  • February 2010
  • December 2009
  • July 2009
  • June 2009
  • May 2009
  • April 2009
  • February 2009
  • December 2008
  • November 2008
  • October 2008
  • July 2008
  • June 2008
  • April 2008
  • March 2008
  • January 2008

Copyright © 2021 NYC Tech Tips

Powered by PressBook Dark WordPress theme