Call + (44) 0843 289 4539

  • No products in the cart.

WordPress PermaLinks not working on localhost

If you have copied your live site for your server to your local machine or even installed the latest version of WordPress on your local machine but now you’re finding none of your links work and you’re unable to click around your site. It may be because your Apache2 Url rewriting module has not been enabled on your ubuntu development localhost.   Fortunately this is really easy to sort out.

What is mod_rewrite

Mod_rewrite is used by Apcahe2 web server to dynamically rewrite website URL’s at the server side.  i.e. When the user asks to go to http://localhost/some_page_on_the_server the mod_rewrite module will translate that to the server as http://localhost/post.php?category=1&post=2, which is then handled by the server to get the appropriate page.

Why use mod_rewrite

It is generally used to improve user and search engine friendliness to expose more memorable and crawl-able URLS.  So effectively to help improve your Search Engine Optimization (SEO).  On a production server this will usually be implemented by default, to improve SEO.

How to enable mod_rewrite on Apache2

The default installation of Apache2 is usually installed with mod_rewrite installed but never enabled.  To check this is the case, we can verify it’s existence.

Open your terminal window ctrl + alt + t

cat /etc/apache2/mods-available/rewrite.load

The server should respond with

LoadModule rewrite_module /usr/lib/apache2/modules/

We can now enable the module

 sudo a2enmod rewrite

Then we need to update your site configuration.  This is assuming you have installed WordPress in the default website

sudo nano /etc/apache2/sites-enabled/000-default.conf

Inside the the file directly under <VirtualHost *:80> on line 1 paste the following

<Directory /var/www/html>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride All
                Order allow,deny
                allow from all

save and exit the file (ctrl + x )

restart your Apache2 web server


sudo service apache2 restart

We now need to create or edit your .htaccess file in your WordPress website directory

sudo nano /var/www/html/.htaccess

You now need to add the following code

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

To ensure that other users are only allowed to read your .htaccess file you need to update the permissions

sudo chmod 644 /var/www/html/.htaccess

You should now be good to go and should be able to browse your site with all the links working!

Follow Me

Gary Woodfine

Helps businesses by improving their technical proficiencies and eliminating waste from the software development pipelines.

A unique background as business owner, marketing, software development and business development ensures that he can offer the optimum business consultancy services across a wide spectrum of business challenges.
Follow Me