rariley3
By:
rariley3

Changing Wordpress Permalink Settings

October 16, 2014 6.9k views

I'm attempting to change the permalink settings within Wordpress, but when I change it from the default to 'post name' I get the following error:

"If your .htaccess file were writable, we could do this automatically, but it isn’t so these are the mod_rewrite rules you should have in your .htaccess file. Click in the field and press CTRL + a to select all."

The 'field' contains the following text:

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

My system:

I've installed the latest Wordpress using the 'one-click' install DigitalOcean offers on top of an Ubuntu 14.04 LAMP droplet.

What I've done so far:

I've updated my .htaccess file within /var/www/ to include the above .htaccess text suggested by Wordpress.

Steps I've taken so far, based on previous help within these forums:

  1. I've changed the permissions for the .htaccess file several times. I've tried chmod -v 666 and chmod -v 766 and chmod -v 777. After each chmod, I've submitted the 'service apache2 restart' command. None of these permission changes have worked. For security reasons, my last permission change has been: chmod -v 666 .htaccess. I've run 'ls -alt .htaccess' to confirm that the changes have been made to allow the file to be read and writable.

  2. I've accessed the apache2.conf file and changed all 'AllowOverride none' instances to say 'AllowOveride all'. I've then submitted the command: 'service apache2 restart' to confirm the changes were made.

  3. I've include the following to the /etc/apache2/sites-available/000-default.conf file:

<Directory "/var/www/html">
AllowOveride all
</Directory>

And again submitted the command, 'service apache2 restart' to confirm changes.

However, I still receive the same error whenever I try to update the permalink option within the Wordpress panel.

Does anyone have any other suggestions? I've googled as much as I can. Any additional help would be GREATLY appreciated.

Thanks,

Richard

1 comment
  • when you change permalinks, sometimes you must click the save button twice...or at least you used to have to. I am not sure if they fixed that yet in WordPress.

    Also, make sure rewrite is enabled in Apache with:

    sudo a2enmod rewrite
    
3 Answers

I'll try the double save option - thanks for the tip. What a strange 'bug'!

Also, I've already enabled rewrite - however, should I do this command at a certain level? I think previously I've done this in the /var/www folder - perhaps I should go up to root? Does it make a difference?

  • UPDATE: The double save option did not work for me. To be safe, I've submitted the command:

    sudo a2enmod rewrite
    

    to the root folder and restarted the apache server. I still receive the same error.

Also, a couple more points:

  1. In my /etc/apache2/apache2.conf file, the Servername is that of the droplet's ip address NOT 'localhost' - does this matter? Some fixes suggest including: Servername localhost

  2. I have no html folder or file in my /var/www folder - some of the coding within the apache2.conf points to /var/www/html. Why is this?

  3. Should I try defining the site_url within wp-config? If so, how would I do this?

  • Do your logs tell you anything?

    sudo tail -f /var/log/apache2/error.log
    

    I once had an error on my .htaccess that was preventing things from working correctly.

    Here is a working site.conf ...might be of some help:

    <VirtualHost *:80>
    ServerAdmin webmaster@yoursite.com
    
        DocumentRoot /var/www/yoursite.com
    
        <Directory /var/www/yoursite.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 None
            Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
            Order allow,deny
            Allow from all
        </Directory>
    
        ErrorLog ${APACHE_LOG_DIR}/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>
    ServerAlias www.yoursite.com
    ServerName yoursite.com
    
    </VirtualHost>
    
  • My error log contains the following information:

    [Thu Oct 16 11:28:45.290065 2014] [mpm_prefork:notice] [pid 23317] AH00169: caught SIGTERM, shutting down
    [Thu Oct 16 11:28:46.299058 2014] [mpm_prefork:notice] [pid 23377] AH00163: Apache/2.4.7 (Ubuntu) PHP/5.5.9-1ubuntu4.4 configured -- resuming normal operations
    [Thu Oct 16 11:28:46.299160 2014] [core:notice] [pid 23377] AH00094: Command line: '/usr/sbin/apache2'
    [Thu Oct 16 11:30:30.721520 2014] [mpm_prefork:notice] [pid 23377] AH00169: caught SIGTERM, shutting down
    [Thu Oct 16 11:30:31.773939 2014] [mpm_prefork:notice] [pid 23437] AH00163: Apache/2.4.7 (Ubuntu) PHP/5.5.9-1ubuntu4.4 configured -- resuming normal operations
    [Thu Oct 16 11:30:31.774037 2014] [core:notice] [pid 23437] AH00094: Command line: '/usr/sbin/apache2'
    [Thu Oct 16 12:00:25.702466 2014] [mpm_prefork:notice] [pid 23437] AH00169: caught SIGTERM, shutting down
    [Thu Oct 16 12:00:26.735815 2014] [mpm_prefork:notice] [pid 23527] AH00163: Apache/2.4.7 (Ubuntu) PHP/5.5.9-1ubuntu4.4 configured -- resuming normal operations
    [Thu Oct 16 12:00:26.735938 2014] [core:notice] [pid 23527] AH00094: Command line: '/usr/sbin/apache2'
    [Thu Oct 16 22:43:29.386504 2014] [mpm_prefork:notice] [pid 23527] AH00169: caught SIGTERM, shutting down
    [Thu Oct 16 22:43:30.413260 2014] [mpm_prefork:notice] [pid 24910] AH00163: Apache/2.4.7 (Ubuntu) PHP/5.5.9-1ubuntu4.4 configured -- resuming normal operations
    [Thu Oct 16 22:43:30.413371 2014] [core:notice] [pid 24910] AH00094: Command line: '/usr/sbin/apache2'
    [Thu Oct 16 22:51:18.174012 2014] [mpm_prefork:notice] [pid 24910] AH00169: caught SIGTERM, shutting down
    [Thu Oct 16 22:51:19.231248 2014] [mpm_prefork:notice] [pid 25039] AH00163: Apache/2.4.7 (Ubuntu) PHP/5.5.9-1ubuntu4.4 configured -- resuming normal operations
    [Thu Oct 16 22:51:19.231360 2014] [core:notice] [pid 25039] AH00094: Command line: '/usr/sbin/apache2'
    [Thu Oct 16 22:55:49.822107 2014] [mpm_prefork:notice] [pid 25039] AH00169: caught SIGTERM, shutting down
    [Thu Oct 16 22:55:50.846357 2014] [mpm_prefork:notice] [pid 25143] AH00163: Apache/2.4.7 (Ubuntu) PHP/5.5.9-1ubuntu4.4 configured -- resuming normal operations
    [Thu Oct 16 22:55:50.846464 2014] [core:notice] [pid 25143] AH00094: Command line: '/usr/sbin/apache2'
    [Thu Oct 16 22:58:10.381963 2014] [mpm_prefork:notice] [pid 25143] AH00169: caught SIGTERM, shutting down
    [Thu Oct 16 22:58:11.426570 2014] [mpm_prefork:notice] [pid 25227] AH00163: Apache/2.4.7 (Ubuntu) PHP/5.5.9-1ubuntu4.4 configured -- resuming normal operations
    [Thu Oct 16 22:58:11.426683 2014] [core:notice] [pid 25227] AH00094: Command line: '/usr/sbin/apache2'
    
    
  • My /etc/apache2/sites-available/000-default.conf file contains:

    <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
    <Directory "/var/www/html">
        AllowOverride all
    </Directory>
    
            # 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>
    
    # vim: syntax=apache ts=4 sw=4 sts=4 sr noet
    
    

    Perhaps this is the issue? I do not have a /var/www/html directory.

  • That would certainly be a place to make a change.

    ..is your www folder your main folder? Typically you would create your sub-folders inside www, one for each website. Eventually you might want additional sites, and having a sub-folder for each makes organizing them much easier..

    But yes, your conf file is not really set up nicely. Is there another conf file you are working off of?

    You could just make a backup of that one, and then use my example above..just replace yourdomain.com with whatever domain you have...make sure the directory is correct, etc.

  • Hmmm...no, that is the only conf file that I know of other than the wp-conf file that I edit. I'm assuming the wp-conf file is normal, if I recall correctly from my previous work in Wordpress (it's been a couple years). This is what I received after I did the one-click install of Wordpress that digitalocean offers.

    I do not have a sub folder after /var/www - just the numerous wordpress files. Is this normal when doing a one-click install of Wordpress or did the install not go correctly? It's quite late where I'm at, but I will try this change as soon as I wake up and report back.

    Questions:

    1. Can I create a 'my-domain' sub folder and house all the wordpress files in there (i.e., /var/www/my-domain/) or will this break my site? I'm thinking that many files point to files within the /var/www folder, so that innumerable files will have to reflect the change that they're now housed within /var/www/my-domain or is this not true?

    2. If the one-click install did not work properly, would it be better to destroy the droplet and start the process from scratch or is this not necessary (i.e., using the config file you provided while housing my wordpress files in a folder within /var/www will be enough to fix the site)? I'm worried that if this is a patch, that I'll run into problems in the future had the install not been done correctly.

    Any thoughts are appreciated and thanks so much for your assistance so far! It's been very timely and helpful for sure!

  • "Can I create a 'my-domain' sub folder and house all the wordpress files in there (i.e., /var/www/my-domain/) or will this break my site?"

    Yes. and you should. especially if you might like to have other websites on your server.
    the one file that matters is the /etc/apache2/sites-available/yoursite.conf
    as long as that conf file has the information for your website, everything else should fall in line. I believe everything in WordPress is relative, so Wordpress will not know you moved it to a different folder....it looks for things like: /wp-content/themes rather than: /var/www/wp-content/theme

    " I'm thinking that many files point to files within the /var/www folder, so that innumerable files will have to reflect the change that they're now housed within /var/www/my-domain or is this not true?"

    it just seems like that. once you have set up a few sites you will get a better feel for it.

    "If the one-click install did not work properly, would it be better to destroy the droplet and start the process from scratch or is this not necessary (i.e., using the config file you provided while housing my wordpress files in a folder within /var/www will be enough to fix the site)? I'm worried that if this is a patch, that I'll run into problems in the future had the install not been done correctly."

    I normally shy away from one-click installs because one time a web-host came and ran a bunch of updates on a one-click install and broke some very intricate customization I had done in Joomla...broke a major website and took hours to resolve.

    Installing WordPress manually takes a little longer but is worth learning if you plan on running your own server.

    Having said that....it does not matter if you move the website files...as long as all the files are present, WordPress has its own internal updater and does not know what folder it lives in.

  • Thank you for answering my questions!

    I've updated my /etc/apache2/sites-available/000-default.conf file to contain the contents you suggested above, replacing your info with that of my site.

    If others have this issue, I also had to update the file directory within the /etc/apache2/apache2.conf file in order for my site to not throw a 404 error, but once these two changes were made, my site was up and running perfectly.

    However, I still get the same error when I try to change my permalinks settings within the Wordpress admin panel!

    I'm dumbfounded.

    Do you have any other suggestion of what I can try?

  • Also, now that I've created a subdomain for my site, it seems I can no longer install plugins. When I try to install a plugin at the Wordpress admin panel, I get the error that a directory could not be created.

    Do you know if another file needs to be changed?

  • Just wanted to say that this problem is fixed. I destroyed the droplet, created a new one using Ubuntu 14.04 64 bit with the LAMP install and followed the following instructions:

    http://www.howtoforge.com/how-to-install-wordpress-on-ubuntu-14.04-lamp

    I changed some directions - instead of installing my site in the wordpress directory as suggested, I installed everything in the /var/www/html directory so that it would be root (i.e., my website would be www.my-site.com vs www.my-site.com/wordpress, which is just dumb).

    Then, I copied the index.html and info.php files to the /var/www/ directory and everything works flawlessly.

    Thanks again for all of your help!! I learned a lot from your guidance.

  • Glad to hear you got it sorted. It is good experience, especially if you are going to be dinkering with websites much.

    After a while it will take you all of 20 minutes to have a website up and running WordPress.

Just to add another experience. I also found that editing /etc/apache2/apache2.conf so that 'allowoveride' were all set to 'all' worked for me. After restarting apache the links worked instantly.

  • This solved my issue, although I wonder what vulnerabilities are a side effect. After some more experience with digitalocean I'll update if there's a tighter approach. Thanks @mrblanco101 !

  • Thanks, This really worked for me. Also i am a bit concerned just like @makelivedotnet , what is the vulnerabilities when making this "Allowoveride All" on /etc/apache2/apache2.conf

Have another answer? Share your knowledge.