RewriteEngine On
Redirect /index.html example.com/zc2/
Aside: I assume this must be a "typo" in your question, but this mod_alias Redirect
directive is completely invalid (you are missing a protocol from the target URL) - this would break your server with a 500 Internal Server Error - "Redirect to non-URL"!?
Also, RewriteEngine
(mod_rewrite) and Redirect
(mod_alias) are unrelated directives from different Apache modules.
What can I do to fix this?
However, I suspect the "redirect loop" might be caused by a miss-configured WordPress .htaccess
file in the /wp
subdirectory. If you are inadvertently rewriting back to the document root, instead of the /wp
subdirectory, then you'll get a redirect loop.
The Redirect
directive is also "prefix-matching" - it matches any URL that starts with the source URL. If you are intending to redirect a specific path (ie. the document root) it would be preferable to use a RedirectMatch
directive (or mod_rewrite RewriteRule
- see later) instead. For example:
RedirectMatch 302 ^/(index\.html)?$ https://example.com/zc2/
This now only matches /
(or /index.html
) and redirects to example.com/zc2/
.
Using mod_rewrite (RewriteRule
) instead
The mod_alias directive (Redirect
or RedirectMatch
) in the document root .htaccess
file is still processed (inherited) when there are other .htaccess
files in subdirectories (ie. the WordPress /wp/.htaccess
file).
To avoid the redirect in the root .htaccess
file from ever interfering with your WordPress install then change the mod_alias Redirect
(or RedirectMatch
) in your document root .htaccess
file to a mod_rewrite RewriteRule
instead.
For example:
RewriteEngine On
RewriteRule ^(index\.html)?$ https://example.com/zc2/ [R=302,L]
The mod_rewrite directives in the WordPress .htaccess
file at /wp/.htaccess
will completely override the mod_rewrite directives in the parent .htaccess
file (in the document root) - thus avoiding any possibility of conflict. The mod_rewrite directives in the root .htaccess
file are not even processed.
(Note that this is dependent on Apache's default behaviour, where mod_rewrite directives are not inherited.)
Whereas when a mod_alias Redirect
is used, the mod_alias directive in the parent .htaccess
file will still be processed (whether it matches or not is another matter) - possible conflict.
If example.com/
is accessed then the redirect to example.com/zc2/
still occurs.
Note, that I've used 302 (temporary) redirects above. Change these to 301 (permanent) - if that is the intention - only when you have confirmed it's working OK. This is to avoid any potential caching issues.
/wp/.htaccess
file. – MrWhite Nov 7 '18 at 7:52