Apache rewrite proxy only homepage
Try something like the following instead, at the top of the .htaccess
file, before the WordPress front-controller:
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^(index\.php)?$ http://some-other-domain.com/ [P]
The RewriteBase
and RewriteEngine
directives are not required here. The RewriteEngine
presumably already appears later in the file as part of the # BEGIN WordPress
code block (the order is not important).
Note the slash suffix on the substitution string. This is a required part of the URL (you can't have an empty URL-path). If you omit it here, then something else must "fix" it later. In the case of an external redirect then the browser would "fix" it, but there is no "browser" here.
This matches both an empty URL-path and index.php
(in case mod_dir is issuing the subrequest for the directory index before mod_rewrite sends the request through mod_proxy). The condition that checks the REDIRECT_STATUS
env var is necessary in this instance to avoid proxying everything, since the WordPress front-controller rewrites everything to index.php
. The condition ensures that only direct requests are matched, not rewritten requests.
Aside: A RewriteRule
pattern like ^/$
will never match in a .htaccess
context. This would only work if the directive was used in a server (or virtualhost) context.