0

I have a folder structure, like this:

  • forum
    • .htaccess
    • [some more files]
  • forum_english
    • .htaccess
    • [some more files]

forum/.htaccess looks like this:

RewriteEngine on

RewriteCond %{HTTP_HOST} \.(com|net)$ [NC] # just rewrite if the query comes from an english languaged domain
RewriteRule ^(.*)$ ../forum_english/$1

#some more RewriteRules from another forum. I don't know, if I am allowed to show them. They should work well, side by side.

forum_english/.htaccess is the default MyBB-htaccess-File.

Sadly this causes an infinite loop. To prevent this, I have to insert a [L]-Flag which skips the forum_english/.htaccess-file (but the rules in this file should be executed, too!). I also tried the [N=2]-Flag instead ... but still infinite loop.

I use Apache 2.2.17 and have no access to error_logs or the files in /etc/apache2/sites-enabled/.

Any ideas what I did wrong?

3
  • You're missing a rewrite condition telling it to NOT match the target url.
    – user143703
    Apr 6, 2015 at 20:06
  • @yoonix If the condition isn't matched, the normal content of forum/ will be served.
    – Thomas131
    Apr 6, 2015 at 20:33
  • First, $HTTP_HOST is the hostname of yourserver, not the client's. hostname. Second, domains ending in .com and .net exist outside of English-speaking countries. In essence, you're doing the wrong thing and you're doing it wrong.
    – Jenny D
    Apr 14, 2015 at 8:51

1 Answer 1

1

If the user arrives via .com or .net, they would presumably continue to do so after you've rewritten the request to a relative location as shown in your example. In other words, the HTTP_HOST condition will always be true.

The .* regular expression is equivalent to "match (almost) any character 0 or more times," and the ^ (start of string) and $ (end of string) markers won't do anything special for you here, since everything between is matched. Because the pattern will effectively match any string, the resulting path after a rewrite to ../forum_english will match as well.

Essentially, the redirect loop occurs because you guarantee both conditions to always be true.

I think you should do some thinking about the definite conditions that indicate that a rewrite needs to occur. What patterns will occur before (but not after) the user has been redirected? Once you have those conditions figured out, then you can investigate how to create the appropriate mod_rewrite rules.

2
  • You are right that [N] would make an infinitife loop. Thanks for that clarification! But without [L] and [N], it would execute the Rule in forum/ once and then it would jump to forum_englisch and execute the .htaccess there, or did I misunderstand something? In forum_englisch, the .htaccess of forum/ has no affect, didn't it?
    – Thomas131
    Apr 6, 2015 at 20:26
  • I messed up. This answer isn't correct, as I failed to take into account the location/isolation of the .htaccess files. I've recreated your environment with the same file/folder structure and did not encounter the same problem. Apr 6, 2015 at 21:42

Not the answer you're looking for? Browse other questions tagged .