0

I'm trying to get my site to redirect to a certain folder depending on a condition. This condition cannot be done within WP, so...

Anyway.. I've done conditions before, but I keep hitting a wall whenever I do a rewrite, since the site is a Wordpress site.

My redirect is:

RewriteCond %{HTTP_COOKIE} !JVL=NL;
RewriteCond %{REQUEST_URI} !^health-studies/
RewriteRule ^(.*)$ /health-studies/ [L,R,CO=JVL:NL:www.domain.com:7200:/]

So basically.. (depending on the condition of course), it needs to redirect to /health-studies/. Example: When people go to example.com, it needs to redirect to example.com/health-studies/

However.. I'm running into an error: ERR_TOO_MANY_REDIRECTS

What am I missing? (Must be something little..as always)

Additional htaccess code AFTER the above few lines:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^domain.com [NC,OR]
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/\.well-known/acme-challenge/[0-9a-zA-Z_-]+$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^(.*)$ https://www.domain.com/$1 [L,R=301]

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
4
  • 2
    Can you post your full .htaccess code? Without seeing the condition and what other rules are in place, we can only guess.
    – WebElaine
    Commented Jun 28, 2019 at 17:58
  • 1
    The directive you posted (without any condition) is an obvious redirect loop (the error you are seeing), since you are redirecting everything (which naturally includes /health-studies/) to /health-studies/. So, everything would seem to depend on this "condition" that you've not stated? "it needs to redirect to /health-studies" - minor point (or maybe not) but your directive is redirecting to /health-studies/, not /health-studies?
    – MrWhite
    Commented Jun 28, 2019 at 19:09
  • @WebElaine My bad.. I added the conditions and expanded on the rewrite rule. Basically, if the cookie isn't there and the path isn't that subfolder, it needs to go to the subfolder and write the cookie.
    – Malachi
    Commented Jul 5, 2019 at 15:03
  • @MrWhite I agree.. my bad.. I added the condition to the question (plus some additional htaccess lines). Thank you for pointing it out!
    – Malachi
    Commented Jul 5, 2019 at 15:08

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.