WordPress and the .htaccess File

IMPORTANT! PHP 7.4 will no longer read the .htaccess file on WP Engine. We advise moving all custom items to another location and returning the .htaccess file to a default state. Refer to our guide for more information and alternatives.



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.

NOTE: Due to the server stack at WP Engine, we highly advise keeping your .htaccess as default as possible.


.htaccess and WP Engine

The .htaccess file works slightly different on the WP Engine platform because we use a dual web-server combination. 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.

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.

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, however if you wish to extend them you can use WP Engine Advanced Cache plugin or reach out to Support.

NOTE: Cache headers cannot be shortened less than 600 seconds/10 minutes.

php_value and php_flag settings

PHP will be retiring the .htaccess starting with PHP 7.4. To ensure your site is prepared for a smooth transition to PHP 7.4, we no 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

Still need help? Contact support!

We offer support 24 hours a day, 7 days a week, 365 days a year. Log in to your account to get expert one-on-one help.

The best in WordPress hosting.

See why more customers prefer WP Engine over the competition.