So on my site, my shopping cart is located at example.com/zc2

I use this .htaccess file

RewriteEngine On

Redirect /index.html example.com/zc2/

So that anyone that lands on example.com will be redirected to my shopping cart.

All good, but now if I try and install WordPress at example.com/wp then browsers get stuck in a redirect loop.

I am positive it is my badly crafted .htaccess file.

What can I do to fix this?

  • Please post your /wp/.htaccess file. – MrWhite Nov 7 '18 at 7:52
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.


There should be no need to use a redirect rule or condition since your simply redirecting the base to a sub folder and therefore those sub folders if linked too wouldn't need th redirect.

Try something like this in /.htaccess file:

Redirect 301 / https://example.com/zc2/

Then this in your /WordPress/.htaccess file:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /WordPress/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress
  • 2
    That redirect would redirect all sub-paths as well. I don't think it will work. – Stephen Ostermiller Nov 7 '18 at 0:20
  • Yep your right, Its possible to rewrite the base and then rewrite the base again using htaccess in the WordPress folder since that should overwrite previous rules. – Simon Hayter Nov 7 '18 at 10:24

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.