justjon
By:
justjon

How can I fix my Wordpress Permalinks?

February 20, 2015 14.5k views

One of my droplets got compromised and for some reason I cannot get permalinks working on the new droplet. I copied over all code and Apache settings, turned the permalinks off and back on in the WP admin, but the permalinks will not work.

I've tried everything I can think of. What do I need to do to get them working again? Thanks.

1 comment
  • Digital Ocean should really consider a default WordPress droplet which has the URL rewrites enabled by default. This is just standard WordPress stuff and thousands of us have to fumble around with command lines just to get pretty links to work.

    C'mon D.O., you can do it!

8 Answers

On a new apache setup there are two common reasons that Wordpress permalinks would not be working.

1.) Make sure you have enabled mod_rewrite in apache. This can be done by running:

a2enmod rewrite

and then restarting apache

service apache2 restart

2.) Check your virtualhost configuration in /etc/apache2/sites-enabled/ and make sure that it is configured with AllowOverride All instead of the default AllowOverride None for your web root directory. This tells apache it is ok for settings in .htaccess files to override settings.

  • root@XXX:~# a2enmod rewrite
    Module rewrite already enabled

    root@XXX:~# cat /etc/apache2/sites-available/000-default.conf
    <VirtualHost *:80>
    # The ServerName directive sets the request scheme, hostname and port that
    # the server uses to identify itself. This is used when creating
    # redirection URLs. In the context of virtual hosts, the ServerName
    # specifies what hostname must appear in the request's Host: header to
    # match this virtual host. For the default virtual host (this file) this
    # value is not decisive as it is used as a last resort host regardless.
    # However, you must set it for any further virtual host explicitly.
    #ServerName www.example.com
    
    ServerName www.XXX.com
    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/html/XXX.com/
    
    # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
    # error, crit, alert, emerg.
    # It is also possible to configure the loglevel for particular
    # modules, e.g.
    #LogLevel info ssl:warn
    
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
    
    # For most configuration files from conf-available/, which are
    # enabled or disabled at a global level, it is possible to
    # include a line for only one particular virtual host. For example the
    # following line enables the CGI configuration for this host only
    # after it has been globally disabled with "a2disconf".
    #Include conf-available/serve-cgi-bin.conf
    </VirtualHost>
    
    <VirtualHost *:80>
    ServerAlias XXX.com
    ServerAdmin XXX
    DocumentRoot /var/www/html/XXX.com/
    ServerName www.XXX.com
    DirectoryIndex index.html index.php
    <Directory "/var/www/html/www.XXX.com/">
    allow from all
    Options -Indexes
    AllowOverride All
    </Directory>
    CustomLog ${APACHELOGDIR}/XXX.log common
    ErrorLog ${APACHELOGDIR}/XXX-error.log
    
    </VirtualHost>
    
  • Ok. That all looks good. A couple more things to check.

    In your web root is the .htaccess file created by wordpress present? If it is not you can check that your web files are owned by the same user as the apache process in order to allow Wordpress to write this file.

    chown -Rf /var/ww/html/
    
  • -rw-rw-r-- 1 www-data www-data 236 Jan 13 13:19 .htaccess

I just went back and looked at your config file for your site and saw you have virtualhost defined twice...not sure why.

Perhaps simplify that a bit like something like:


<VirtualHost *:80>


ServerName www.XXX.com
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html/XXX.com
ServerAlias  XXX.com


    <Directory /var/www/html/XXX.com>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        allow from all
                Require all granted
    </Directory>

    ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
    <Directory "/usr/lib/cgi-bin">
        AllowOverride All
        Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
        Order allow,deny
        Allow from all
    </Directory>

      CustomLog ${APACHELOGDIR}/XXX.log common
      ErrorLog ${APACHELOGDIR}/XXX-error.log

    # Possible values include: debug, info, notice, warn, error, crit,
    # alert, emerg.
    LogLevel warn

    CustomLog ${APACHE_LOG_DIR}/access.log combined

    Alias /doc/ "/usr/share/doc/"
    <Directory "/usr/share/doc/">
        Options Indexes MultiViews FollowSymLinks
        AllowOverride All
        Order deny,allow
        Allow from all
    </Directory>


</VirtualHost>


and finally, Maybe do (just to be sure) :

sudo chown -R www-data:www-data /var/www

and


sudo chmod -R 774 /var/www  

what are you trying to save your permalinks as?

when you save permalinks, do you get any errors at the bottom of the page?

try saving permalinks twice..click save...click save

  • Permalink structure updated.

    No error messages.

  • what are you trying to save your permalinks as? Are you using Default, Numeric, Post Name, etc...?

  • /%category%/%postname%/

    But I did try other selections from the radio buttons as well.

  • and does your .htaccess file have something like this:

    # 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
    
  • WordPress auto generates this.

    BEGIN WordPress

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

    END WordPress

Maybe do (just to be sure) :

sudo chown -R www-data:www-data /var/www

and

sudo chmod -R 774 /var/www

This is way frustrating. I hope someone can help me out with this. When I click on a permalink the pages fail to load and I get this error from Chrome's console: {"@context":"http:\/\/schema.org","@type":"WebSite","url":"http:\/\/lineangel.com\/","name":"LineAngel"}

I tried this [https://randomwordpresstips.wordpress.com/2013/05/10/enabling-permalinks-on-wordpress-install-ubuntu-12-10/](http://) with no luck.

a2enmod rewrite is enabled
.htaccess file is set to “chmod 666″

My .htaccess file is:

BEGIN WordPress

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

END WordPress

My apache2.conf file is:

ServerRoot "/etc/apache2"
Mutex file:${APACHELOCKDIR} default
PidFile ${APACHEPIDFILE}
Timeout 300
KeepAlive On
MaxKeepAliveRequests 100
KeepAliveTimeout 5
User ${APACHERUNUSER}
Group ${APACHERUNGROUP}
HostnameLookups Off
ErrorLog ${APACHELOGDIR}/error.log
LogLevel crit
IncludeOptional mods-enabled/.load
IncludeOptional mods-enabled/
.conf
Include ports.conf

<Directory />
Options FollowSymLinks
AllowOverride all
<Limit PUT DELETE CONNECT OPTIONS PATCH PROPFIND PROPPATCH MKCOL COPY MOVE LOCK UNLOCK>
deny from all
</Limit>
</Directory>

<Directory /var/www>
Options FollowSymLinks
AllowOverride FileInfo
</Directory>

<Directory /usr/share>
AllowOverride all
Require all granted
</Directory>

AccessFileName .htaccess

<FilesMatch "^\.ht">
Require all denied
</FilesMatch>

AccessFileName .htaccess

<FilesMatch "^\.ht">
Require all denied
</FilesMatch>

LogFormat "%v:%p %h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" vhost_combined
LogFormat "%h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %O" common
LogFormat "%{Referer}i -> %U" referer
LogFormat "%{User-agent}i" agent

IncludeOptional conf-enabled/.conf
IncludeOptional sites-enabled/
.conf

<DirectoryMatch ^.*/wp-content/uploads/>
AllowOverride all
phpflag engine off
php
admin_value engine Off
</DirectoryMatch>

<DirectoryMatch ^.*/wp-content/blogs.dir/>
AllowOverride all
phpflag engine off
php
admin_value engine Off
</DirectoryMatch>

AuthType Basic AuthName "Restricted Area" AuthUserFile /etc/apache2/.htpasswd Require valid-user

<VirtualHost *:80>
ServerAdmin webmaster@lineangel
DocumentRoot /var/www
Servername localhost
ServerAlias lineangel www.lineangel

<Directory /var/www/html/lineangel.com>
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order allow,deny
allow from all
</Directory>
</VirtualHost>

My 000-default.conf is:

<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
#ServerName www.example.com

ServerAdmin webmaster@localhost
DocumentRoot /var/www/html

# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn

ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined

# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
  <Directory /var/www/html/lineangel.com>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride all
    Order allow,deny
    allow from all
</Directory>

</VirtualHost>

vim: syntax=apache ts=4 sw=4 sts=4 sr noet

Any help would be greatly appreciated!

I was able to get it working. I guess there was a secondary issue with one of the plugins causing the pages not to load.

I had the same issue and after some research I found this solution:

http://haydenjames.io/disable-htaccess-wordpress-performance/

Basically, you need to add the information that is found in the WordPress .htaccess file to the main apache configuration file. .htaccess files are only meant to be used in situations where you don't have access to the main configuration file, like when you are using shared hosting.

If you're using Digital Ocean you have access to the main configuration file, so you shouldn't be using .htaccess files and you should have "AllowOveride None" set to increase apache performance.

Have another answer? Share your knowledge.