0

I am having an issue trying to set up multiple RewriteBase directories for a production / live environment. I have followed the guidance provided at:

Many RewriteBase in one .htaccess file?

With mod_rewrite can I specify a RewriteBase within a RewriteCond?

This broadly seems to work except when the base directory is the root (i.e. "/") as follows:

RewriteCond %{HTTP_HOST} ^localhost/tla-test/(.)$ [OR]
RewriteCond %{HTTP_HOST} ^192.168.0.200/tla-test/(.)$
RewriteRule ^(.*)$ tla-test/index.php&page=$1 [L]

RewriteCond %{HTTP_HOST} ^test.townshendla.com/(.)$
RewriteRule ^(.*)$ /index.php&page=$1 [L]

#Send any reqests to the index.php file
RewriteCond %{REQUEST_FILENAME}    !-f
RewriteCond %{REQUEST_FILENAME}    !-d
RewriteRule .*                     index.php

The first rewrite condition works perfectly. The second rewrite condition keeps coming up with an error 500 whenever it kicks in. As it's 1and1 I cant get the Apache error logs but if I try and replicate on a test environment I get the following error (please note this could be unrelated):

AH00124: Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace.

Any thoughts would be much appreciated.

Community
  • 1
  • 1
Hugh T
  • 1
  • 1
  • 1
    `HTTP_HOST` only matches hostname not URI – anubhava Nov 12 '16 at 10:32
  • You're rewriting your rewritten URLs. First understand that [mod rewrite rules are applied more than once](https://httpd.apache.org/docs/2.4/rewrite/tech.html#InternalRuleset). – Walf Nov 13 '16 at 04:34

1 Answers1

0

Thanks for both your help. Firstly anubhava you were right about HTTP_HOST and secondly Walf your pointer was invaluable, it led me to this page with a detailed explanation of someone who was having a similar issue:

Mod_Rewrite unexpected behavior L flag

Overall it looks like the problem was that the file / directory checks were going into a loop, the code that seems to fix this is:

RewriteCond %{HTTP_HOST} ^(localhost|192.168.0.200)$
RewriteCond %{REQUEST_FILENAME}    !-f
RewriteCond %{REQUEST_FILENAME}    !-d
RewriteRule ^(.*)$ /tla-test/index.php?page=$1

RewriteCond %{HTTP_HOST} !^(localhost|192.168.0.200)$
RewriteCond %{REQUEST_FILENAME}    !-f
RewriteCond %{REQUEST_FILENAME}    !-d
RewriteRule ^(.*)$ /index.php?page=$1

Thanks

Hugh

Community
  • 1
  • 1
Hugh T
  • 1
  • 1