Hey all -
I’ve got a website that we’re migrating to ExpressionEngine 6 from 2, and we’re having the strangest issue. The main page loads up okay, but all I get are 404s whenever I try to navigate to any other part of the website. We’re using the basic .htaccess file you mention here, and while that DOES remove the “index.php” from our URL, all of our links 404.
Then, if I move the contents of that .htaccess file into the actual Apache Httpd config file for the site (we have root access on our server), links seem to work, but CSS doesn’t load. I’m really not sure what’s happening (or where to find more verbose logs within the application itself) please help.
Server Specs:
Software | Version |
---|---|
OS | Alma Linux 8.6 |
Apache HTTPD | 2.4.37 |
MariaDB | 10.3.32 |
PHP | 8.0.20 |
I guess I checked and, again, I’m just using the super basic one from the ExpressionEngine docs page I linked in my original post:
$ cat /var/www/html/example_com/.htaccess
:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
# Removes index.php from ExpressionEngine URLs
RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
RewriteCond %{REQUEST_URI} !/system/.* [NC]
RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,NE,L]
# Directs all EE web requests through the site index file
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
</IfModule>
Our site is suuuuper basic, though - basically just a homepage with links to various product pages, about us, and a contact form. There’s no crazy extra functionality (aside from this little part number generator on one of the pages - but it isn’t even done yet and only lives on that one page!), so I don’t see why we’d need any of those extra steps from that .htaccess documentation. Add to that that that’s pretty much verbatim the same .htaccess file we had for our EE2 site, and… I’m at a bit of a loss. :(
So, I figured it out! Turns out .htaccess files don’t actually have any effect on the way Apache serves up files without an AllowOverride
directive in the site’s Apache config file. Since ExpressionEngine’s .htaccess file pretty much only makes use of Apache’s mod_rewrite module, you can tighten that AllowOverride
directive to simply be AllowOverride FileInfo
(as opposed to AllowOverride All
, which might be a little too broad of a security posture and needlessly increase your site’s attack surface).
The AllowOverride
directive cannot exist directly within the context of a VirtualHost
directive, so it’s necessary to place it within a <Directory>
directive nested within your ExpressionEngine site’s <VirtualHost>
directive, like so:
<VirtualHost *:80>
ServerName staging.example.com
ServerAlias staging.example.com
Redirect permanent / https://staging.example.com
</VirtualHost>
<VirtualHost *:443>
ServerAdmin webmaster@example.com
DocumentRoot "/var/www/html/example_com"
ServerName staging.example.com
ServerAlias staging.example.com
<Directory /var/www/html/example_com>
AllowOverride FileInfo
</Directory>
CustomLog "/var/www/html/example_com/logs/httpd/example_com_access.log" common
ErrorLog "/var/www/html/example_com/logs/httpd/example_com_error.log"
SSLEngine on
SSLCertificateFile /etc/httpd/ssl/staging.example.com.crt
SSLCertificateKeyFile /etc/httpd/ssl/staging.example.com.key
</VirtualHost>
Figured I’d be a good internet netizen and post my solution for the next poor soul who gets caught at this issue.
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.