URL rewrite not working, a2enmod active, using Override All, .htaccess correct

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.

Read More

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?

Related posts

2 comments

  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
    
  2. 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.

Comments are closed.