Содержание:
Hello! I was tasked by SEO specialist to remove index.php
from the URLs on a WordPress site.
Usually, this can be handled via .htaccess
, but in this case I ran into a couple of nuances:
- We need to distinguish the request type – regular GET requests versus AJAX/REST calls.
- Is the request targeting the public-facing site or the admin area?
- If the site uses a caching plugin – specifically WP Super Cache in «expert» mode – the
.htaccess
rules may not take effect.
After struggling to combine various rules, I decided to write a lightweight MU plugin. However, because WP Super Cache doesn’t allow MU plugins to run unless «Late Initialization» is enabled, I ended up bundling the same logic as a mini-plugin for WPSC. You can check out the final result in the GitHub repo, and I’m also including the archive of the current 1.2.1 release:
Functionality
- Checks the request type – only acts on GET requests.
- Ignores calls to WordPress paths (those containing “wp-”), including the admin area.
- Allows you to choose whether to add or remove a trailing slash via the
$remove_trailing_slash
option. - If all conditions are met, issues a 301 redirect to the URL without
index.php
. - When triggered, adds an HTTP header:
X-HIDDEN-MU-INDEXPHPREDIR: active
orX-HIDDEN-WPSCPlugin-INDEXPHPREDIR: active
Installation
- Unpack the plugin into the root of your site (or into the subdirectory containing
wp-content
). - Activate the plugin named “WP Super Cache – index.php redirect fix.”


