Permalinks are not working in wordpress.

Posted August 27, 2018 9.4k views

I have looked at all the similar questions, and I am still not able to get permalinks to work. I have confirmed that .htaccess is being accessed. I have also confirmed that mod_rewrite is enabled, and working, and even working in .htaccess. I will explain how I have tested this.

When things first weren’t working, I removed the rewrite rule in my /etc/apache2/sites-available/ and confirmed that I was able to get the site to load without https. I then inserted a bad line at the top of my .htaccess file, and it gave me a 500 error. I then removed that line, and added the rewrite rules that were originally in my file to the .htaccess file, and I inserted it between <IfModule mod_rewrite.c></IfModule> tags and tested it. I was redirected to the secure site. I am able to go to the page if I leave the default permalinks alone, but when I change them to anything besides “plain”, I get a 404 error.

Here is my .htaccess file as it sits now. The wordpress rules don’t work, but the HTTPS rules do.

# 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]

# END WordPress

# HTTPS Rewrite
<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteCond %{SERVER_NAME} [OR]
    RewriteCond %{SERVER_NAME}
    RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]

# END HTTPS Rewrite

Here is my current file:

<VirtualHost *:80>
    DocumentRoot /var/www/
    ErrorLog /var/www/
    CustomLog /var/www/ combined
    <Directory /var/www/>
        AllowOverride All

sudo a2enmod rewrite tells me “Module rewrite already enabled”

For additional information, I followed How To Install WordPress with LAMP on Ubuntu 18.04. I also followed all the prerequisites, including initial server setup, install a lamp stack, and letsencrypt guide for apache. I even rebuilt the server and started from scratch when it wasn’t working.

Needless to say, I am a bit perplexed. Any help would be appreciated.

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
2 answers

Hello friend!

Check in /etc/apache2/apache2.conf and look for a <Directory> statement referring to /var/www. I’ll bet it has AllowOverride disabled. Try changing that to All, restart Apache, and see if it works.


  • When I do that, I get a “too many redirects” error.

    My question is, doesn’t my virtualhost directive override that AllowOverride thing?

    • That’s good, that means it’s processing your .htaccess now, but what is in your .htaccess is looping redirects. I’m quite sure it exists in this section, but I’m kind of bad at eyeballing regex:

          RewriteCond %{SERVER_NAME} [OR]
          RewriteCond %{SERVER_NAME}
          RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]

      That statement is, I believe, causing the site to redirect to itself in a loop.

      As for the other, the one in apache2.conf does override it seems.

      • Okay, when I put those lines back in the original file, it works. That was written by letsencrypt. That is something that needs to be in the tutorial.

  • Thanks so much Jarland, this solved an issue I was struggling with! I agree w/ PoDuck that adding something about this to the tutorial could be super helpful!