Permalinks are not working in wordpress.

August 27, 2018 2.5k views
Apache WordPress

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/mysite.com.conf 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 mysite.com.conf 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]
</IfModule>

# END WordPress

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

# END HTTPS Rewrite

Here is my current mysite.com.conf file:

<VirtualHost *:80>
    ServerAdmin webmaster@mysite.com
    DocumentRoot /var/www/mysite.com/html
    ServerName mysite.com
    ServerAlias www.mysite.com
    ErrorLog /var/www/mysite.com/logs/error.log
    CustomLog /var/www/mysite.com/logs/access.log combined
    <Directory /var/www/mysite.com/html/>
        AllowOverride All
    </Directory>
</VirtualHost>

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.

2 Answers
jarland MOD August 27, 2018
Accepted Answer

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.

Jarland

  • 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} =mysite.com [OR]
          RewriteCond %{SERVER_NAME} =www.mysite.com
          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.

Have another answer? Share your knowledge.