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
The server should respond with
We can now enable the module
Then we need to update your site configuration. This is assuming you have installed WordPress in the default website
Inside the the file directly under
<VirtualHost *:80> on line 1 paste the following
save and exit the file (
ctrl + x )
restart your Apache2 web server
We now need to create or edit your .htaccess file in your WordPress website directory
You now need to add the following code
To ensure that other users are only allowed to read your .htaccess file you need to update the permissions
You should now be good to go and should be able to browse your site with all the links working!