18

In my local machine, wordpress permalinks not working. After research I found that wordpress not creating .htaccess file.

For this I followed below steps.

  1. Manually create a ".htaccess" file and save it in your main WordPress directory. (This is the one with the wp-admin, wp-includes, and wp-content folders.)

  2. Go to the Ubuntu terminal and type:

    sudo chown -v :www-data "/FilePathHere/.htaccess"

You should see a line printed saying that the (group) file ownership has been changed to www-data (Apache2).

  1. Give Apache2 write access to the file:

    sudo chmod -v 664 "/FilePathHere/.htaccess"

You should see a line printed saying that the mode of the file has been retained.

  1. Next, we have to allow WordPress to write to the .htaccess file by enabling mod_write in the Apache2 server. Type the following in the terminal:

    sudo a2enmod rewrite

You should see a line printed saying that it is enabling mod rewrite and reminding you to restart the web server

  1. So let's do that. Restart the web server, Apache2, for the changes to take effect by typing:

    sudo /etc/init.d/apache2 restart

We are all done with the command line prompt; you can close the command line window now.

  1. Go into your WordPress admin panel (i.e. http://Domain/wp-admin). Go to the Settings --> Permalinks and select the permalink format of your choice. Hit the "Save Changes" button.

All steps were successful. But even that Permalinks not worked.

Is anything else settings required to work permalinks properly.

2 Answers 2

30

In terminal type:

sudo gedit /etc/apache2/apache2.conf

Find:

<Directory /var/www/>

And make sure the AllowOverride directive is set to All.

7
  • 4
    sudo service apache2 restart ---- afterward to make the change take effect. Apr 30, 2016 at 3:59
  • 2
    I had to change AllowOveride to All for /var/www/html Feb 14, 2018 at 16:27
  • 1
    This solution by SLH still works 2020 Jan 28, 2020 at 20:53
  • 1
    This solution worked with me, 2021! :D Ubuntu 20.04 - apache2 Oct 26, 2021 at 0:00
  • 1
    Thank you @HeatfanJohn your solution helped me. It needs the project directory access Jan 18, 2022 at 17:39
6

In order to follow .htaccess redirects, it should be mentioned that Apache's <mod_rewrite> module needs to be enabled.

You can do this from command line on the server using the following commands:

sudo a2enmod rewrite
sudo service apache2 restart
1
  • 3
    i cannot express the amount of happiness i just got from reading this answer
    – Pants
    Jan 13, 2021 at 2:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.