WordPress and the .htaccess File
IMPORTANT! WP Engine has deprecated the .htaccess file. Refer to our guide for more information and alternatives.
Some websites will retain temporary grandfathered support of the .htaccess. Learn more here.
The .htaccess is a config file for your web server. When the file is loaded to the root directory of your website and is loaded through the web server, the server executes the directives listed in the file. This allows for additional functionality such as IP blocking & redirect rules.
.htaccess and WP Engine
The .htaccess file works differently on the WP Engine platform because we use a dual web-server combination of Apache and Nginx. This means settings and directives in the .htaccess file will only apply for uncached requests.
The .htaccess is processed by Apache, which does not serve traffic on WP Engine. This is incredibly important when it comes to items such as redirects and headers, as Nginx is actually serving traffic instead.
Redirects
Most requests to your site are cached. This means most requests will never reach the .htaccess file for any rules (like redirects) there to have an effect.
Instead, set them on Nginx directly by adding redirects to your User Portal. Redirects in the User Portal will load faster and perform consistently.
If you have a very large number of redirects (1000+), add them to a plugin instead to ensure performance isn’t impacted.
Cache Headers
Static assets are served directly by Nginx. The .htaccess is processed by Apache. This means if you’re trying to set headers for static assets within the .htaccess, the image will have already been served to your visitor before ever reaching the .htaccess to place a header.
We’ve set these for you already. By default, page cache is set to 600 seconds, or 10 minutes. Static assets (such as images) are set to 365 days.
Cache headers cannot be shortened less than 600 seconds/10 minutes.
php_value and php_flag settings
WP Engine does not longer suggest modifying php_value
or php_flag
settings in the .htaccess file.
Refer to our guide for alternatives.
.htaccess Defaults
As part of troubleshooting errors on your site, you may need to temporarily place a default .htaccess. Once you’ve made a backup of the current .htaccess, copy the contents appropriate for you WordPress configuration and upload a new .htaccess file. The .htaccess is a cached file, if you make any updates be sure to purge cache after.
Default WordPress .htaccess
# BEGIN WordPress RewriteEngine On RewriteBase / RewriteRule ^index.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] # END WordPress
Subdomain Multisite .htaccess
RewriteEngine On RewriteBase / RewriteRule ^index.php$ - [L] # add a trailing slash to /wp-admin RewriteRule ^wp-admin$ wp-admin/ [R=301,L] RewriteCond %{REQUEST_FILENAME} -f [OR] RewriteCond %{REQUEST_FILENAME} -d RewriteRule ^ - [L] RewriteRule ^(wp-(content|admin|includes).*) $1 [L] RewriteRule ^(.*.php)$ $1 [L] RewriteRule . index.php [L]
Subdirectory Multisite .htaccess
RewriteEngine On RewriteBase / RewriteRule ^index.php$ - [L] # add a trailing slash to /wp-admin RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L] RewriteCond %{REQUEST_FILENAME} -f [OR] RewriteCond %{REQUEST_FILENAME} -d RewriteRule ^ - [L] RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) $2 [L] RewriteRule ^([_0-9a-zA-Z-]+/)?(.*.php)$ $2 [L] RewriteRule . index.php [L]
Which .htaccess do I need?
Open the wp-config.php file, also located in your site’s root, and locate one of the following defines. If you see neither define, use the default file.
Subdomain:define('SUBDOMAIN_INSTALL', true);
Subdirectory:define('SUBDOMAIN_INSTALL', false);
NEXT STEP: WP Engine Platform Settings