WordPress permalinks not working

wordpress

If your permalinks are not working and you are seeing a “page not found” when you try to access them. It might be because your .htaccess file is not being seen by apache2. WordPress adds redirects and rewrites to the .htacces file. By reading the .htaccess file apache2 knows how to handle your permalinks. A possible fix might be to change the virtual host configuration just a little.

Find the file which contains your virtual host configuration (usually /etc/apache2/sites-available/000-default.conf on a default install).

Add the following snippet to the virtual host config of the site you are working on:

<Directory "/FULL_PATH_TO_WEBSITE_DIR">
	AllowOverride All
</Directory>

The entire config (default) will look something like this :

<VirtualHost *:80>
	# The ServerName directive sets the request scheme, hostname and port that
	# the server uses to identify itself. This is used when creating
	# redirection URLs. In the context of virtual hosts, the ServerName
	# specifies what hostname must appear in the request's Host: header to
	# match this virtual host. For the default virtual host (this file) this
	# value is not decisive as it is used as a last resort host regardless.
	# However, you must set it for any further virtual host explicitly.
	#ServerName www.example.com

	ServerAdmin webmaster@localhost
	DocumentRoot /var/www/html
	<Directory "/FULL_PATH_TO_WEBSITE_DIR">
	       AllowOverride All
        </Directory>

	# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
	# error, crit, alert, emerg.
	# It is also possible to configure the loglevel for particular
	# modules, e.g.
	#LogLevel info ssl:warn

	ErrorLog ${APACHE_LOG_DIR}/error.log
	CustomLog ${APACHE_LOG_DIR}/access.log combined

	# For most configuration files from conf-available/, which are
	# enabled or disabled at a global level, it is possible to
	# include a line for only one particular virtual host. For example the
	# following line enables the CGI configuration for this host only
	# after it has been globally disabled with "a2disconf".
	#Include conf-available/serve-cgi-bin.conf
</VirtualHost>

The “AllowOverride All” line might be optional as this setting defaults to All when not specifically added.
Restart your apache2 and your .htaccess will now be enabled. If you want to know more about .htaccess files, check out : https://httpd.apache.org/docs/current/howto/htaccess.html

 

Leave a Reply

Your email address will not be published. Required fields are marked *