Without index.php in permalinks I get 404 across site

Adding junk doesn’t do anything either.

That suggests your .htaccess file is not being processed at all. You need to set AllowOverride All in the appropriate <Directory> container in the main server config (or <VirtualHost> container) to enable the parsing of per-directory .htaccess files (to allow .htaccess directives to override the server config).

The FollowSymLinks (or SymLinksIfOwnerMatch) options also need to be enabled for mod_rewrite to function. (Although FollowSymLinks is enabled by default.) This can be enabled in the server config or .htaccess file.

For example:

<Directory /var/www/directory_name>
    AllowOverride All
    Options +FollowSymLinks

    # etc...    

    Require all granted
</Directory>

Where /var/www/directory_name is your DocumentRoot and location of the .htaccess file.

Strictly speaking, you only need AllowOverride FileInfo to enable the use of mod_rewrite in .htaccess. However, you would need to enable more groups if you later used authorization directives, directory listings, etc.

As always, after making any changes to the server config you need to restart Apache for the changes to take effect.

UPDATE: Perhaps there is an issue with my SSL conf?

Since you are redirecting everything to HTTPS in your server config, you need to apply the above <Directory> section to your <VirtualHost *:443> container. Applying this to <VirtualHost *:80> (ie. HTTP) is not required and will do nothing here.

Aside:

RewriteEngine on
RewriteCond %{SERVER_NAME} =domain.com [OR]
RewriteCond %{SERVER_NAME} =www.domain.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]

Your HTTP to HTTPS redirect is overly complex and can be simplified to a single mod_alias Redirect directive – the additional overhead of mod_rewrite is not required here.

You should also canonicalise the hostname (www or non-www) here also.

For example:

Redirect 301 / https://www.example.com/

Leave a Comment