Enabling pretty permalinks for Wordpress - apache setup doesn't work

This error probably has a fairly simple solution, but I have been looking for it for a long time and still do not get the error. I think I tried everything I could.

Problem: when I include fairly permalinks to my Wordpress installation (so that it uses /% postname% /), it does not work. I get 404 on all pages except the main page.

This http://codex.wordpress.org/Permalinks page tells me that the permalink requirements will work:

  • Apache web server with mod_rewrite installed.
  • In the WordPress home directory,
    • FollowSymLinks option enabled
    • FileInfo directives allowed (e.g. AllowOverride FileInfo or AllowOverride All)
    • .Htaccess file (if this file is missing, WordPress will try to create it when you activate the "pretty" permalinks)
    • If you want WordPress to automatically update the .htaccess file, WordPress will have to write access to the file.

An Apache web server is installed, the mod_rewrite module was loaded with the a2enmod rewrite command (and the server was restarted several times after). Thus, in / etc / apache 2 / mods-enabled there is a symbolic link for rewrite.load. In addition, when I run the phpinfo command, I see that the mod_rewrite module is loaded. You can also check it out here: http://namorti.com/phpinfo.php

Then in / etc / apache 2 / sites-enabled there was no "default" presence. I copied 000-default.conf by default and subsequently changed the default value. It contains the following: DocumentRoot / var / www

<Directory /> Options FollowSymLinks Indexes AllowOverride FileInfo </Directory> 

So, as far as I can tell, FollowSymLinks is enabled, and FileInfo directives are enabled.

As for the last two points, in my home wordpress directory (/var/www),.htaccess is present and written Wordpress (I updated the permalink structure several times and updated the .htaccess file accordingly). Now it contains the following:

 # 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 

So, as far as I know, this MUST work. I restarted the server (service apache2 restart) several times. I do not see what I am missing. Who has a key?

Thanks in advance!

* EDIT *

So, I did what calcinai told me ... I edited the file / etc / apache 2 / sites-enabled / default (containing vhost). Now it looks like this:

 <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 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 www.namorti.com DocumentRoot /var/www <Directory /var/www> Options MultiViews AllowOverride None Order allow,deny allow from all RewriteEngine On RewriteBase / RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </Directory> # Available loglevels: trace8, ..., trace1, debug, info, notice, warn, # error, crit, alert, emerg. # It is also possible to configure the loglevel for particular # modules, eg #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 

I restarted apache again, but unfortunately it still doesn't work. Honestly, this would surprise me, because moving directives from the .htaccess file to vhost would work if htaccess would work on it, since everything else seemed to me quite correct ...

Any other suggestions? Thanks for this!

+6
source share
4 answers

I decided it myself.

It related to the file "000-default.conf" - I copied it to "default" and edited the "default", as I mentioned in my question.

Obviously, the service uses the "000-default.conf" file for itself. By copying the "default" file back to "000-default.conf" and restarting the apache service, everything will work now.

One caveat: the calcinai suggestion looks like it should work, but with its suggestion in my vhost in the correct file "000-default.conf" I got 403 Forbidden error. When I replaced its contents with my original content

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

And then restarting the apache service again, it all worked.

Thanks calcinai for your efforts to try and help me :)

+3
source

Make sure that the AllowOverrides directive AllowOverrides set to all in vhost - that tells apache to search for .htaccess files in the feed .

The best solution is to actually translate the rewrite directives into vhost, since you obviously have write access to the file. When you enable AllowOverrides, apache will search the directory and all parent directories for .htaccess files for each request, which can be a big success.

For Wordpress, your ghost should look something like this:

 <VirtualHost *:80> ServerName example.com DocumentRoot /var/www/site <Directory /var/www/site> Options Indexes FollowSymLinks AllowOverride None Order allow,deny allow from all RewriteEngine On RewriteBase / RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </Directory> </VirtualHost> 
+12
source

This may help you solve this problem:

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

After spending a lot of time, this is what worked successfully on my Linux LAMP server. The following changes are necessary for me to make it work perfectly,

  • Add this to your /etc/hosts file.

     127.0.0.1 sitename.com 
  • Add the host entry as follows in the path /etc/apache2/sites-available/sitename.com.conf

     <VirtualHost *:80> ServerAdmin webmaster@localhost ServerName sitename.com DocumentRoot /var/www/sitename.com/public_html <Directory /> Options FollowSymLinks AllowOverride None </Directory> <Directory /var/www/sitename.com/public_html> Options Indexes FollowSymLinks MultiViews AllowOverride All Order allow,deny allow from all </Directory> ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined </VirtualHost> 
  • Create a symbolic link to sites.

     sudo ln -s /etc/apache2/sites-available/sitename.com.conf /etc/apache2/sites-enabled/sitename.com.conf 
  • Restart apache with the command

     sudo service apache2 restart 

This works great for me. Instructions for adding a host entry taken from https://www.digitalocean.com/community/questions/wordpress-permalinks-not-working-on-ubuntu-14-04

0
source

Source: https://habr.com/ru/post/953733/


All Articles