2

The issue

I have installed a Wordpress. I have turned on Pretty Permalinks (Post name). Any page other than the homepage is a 404 Not Found. This seems to indicate a rewrite issue.

My set up

Ubunutu 14.04 Using localhost as my URL My apache config is /etc/apache2/sites-available/000-default.conf My wordpress is located at /var/www/wordpress/ My relevant htaccess is located at /var/www/wordpress/.htaccess

What I've tried

When I run a2enmod rewrite I get

Module rewrite already enabled

My .htaccess

# 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

My 000-default.conf file apache config

<Directory /var/www/wordpress/>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride All
    Order allow,deny
    allow from all
</Directory>

I've tried all the answers at the canonical question for this.

How to enable mod_rewrite for Apache 2.2

My question

Why is my rewrite not working?

Community
  • 1
  • 1
Goose
  • 4,764
  • 5
  • 45
  • 84

2 Answers2

1

I found that I needed to edit the apache config at /etc/apache2/apache2.conf and change the /var/www/ Directory to AllowOverride All

<Directory /var/www/>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride All
    Order allow,deny
    allow from all
</Directory>

I would have thought that my 000-default.conf would have overrode this but that was not the case and this fixed the issue.

Goose
  • 4,764
  • 5
  • 45
  • 84
  • My apache2.conf is set to `None` on `/` and `/var/www` and rewrite is working fine. – Pinke Helga May 16 '16 at 19:48
  • @Quasimodo'sclone Agreed it is unexpected, however it fixed the issue for me and I didn't seen this answer to this issue on StackOverflow so this may be helpful to others. – Goose May 16 '16 at 19:57
  • This answer was already posted on the [question](http://stackoverflow.com/questions/869092/how-to-enable-mod-rewrite-for-apache-2-2) you've linked (37 upvotes). It seems to solve config problems, however, it's a strange behavior (not working without) and I wouldn't like to have such settings on productive systems. – Pinke Helga May 16 '16 at 20:07
  • @Quasimodo'sclone That answer instructs to edit `/etc/apache2/sites-enabled/000-deafult` which I already have tried unsuccessfully. I agree it's not ideal, and no it will not be used on production. If you can find a more direct solution, I will accept. – Goose May 16 '16 at 20:09
  • Can you post your complete 000-default.conf? And have you enabled this site config? Is there a symlink in sites-enabled? – Pinke Helga May 16 '16 at 20:16
  • I took a look at the rest of `000-default.conf` and saw `DocumentRoot /var/www/html`. This looks wrong. If you think this is causing the issue, post it as an answer and I'll accept. – Goose May 16 '16 at 20:34
1

Steps to check proper vhost configuration: Check if there is a "vhostname.conf" file in your "sites-available" directory. Then check if there is a valid symlink to that file in "sites-enabled" directory. You can create a missing site symlink by a2ensite vhostname. Open this file in an editor. It should contain something like

<VirtualHost *:80>
    ServerAdmin webmaster@sitename.net
    ServerName  sitename.net
    ServerAlias www.site-name.net

    DocumentRoot /var/www/site-folder/htdocs

    <Directory /var/www/site-folder/htdocs/>
            Options Indexes FollowSymLinks MultiViews
            DirectoryIndex index.php7 index.php5 index.php index.html
            AllowOverride All

# apache 2.2 and below only (following 3 lines)
            Order allow,deny
            Allow from all
            Deny from none

# apache 2.4 only
            Require all granted  
    </Directory>

Ensure that the DocumentRoot folder has a matching <Directory /path/to/docroot> block. Place into this block AllowOverride All or any selective permission you want to allow to be overridden in ".htaccess".

Ensure the rewrite module is enabled.

sudo a2enmod rewrite

After modifying configurations don't forget to restart/reload apache.

sudo apache2ctl graceful

Check if the module and the vhost config was loaded.

apache2ctl -t -D DUMP_VHOSTS
apache2ctl -t -D DUMP_MODULES
Pinke Helga
  • 6,378
  • 2
  • 22
  • 42