@@ -22,23 +22,41 @@ RewriteEngine on
2222
2323DocumentRoot "$REMOTE_SRC"
2424
25- # Direct php requests to the php-X.X container
26- RewriteCond %{HTTP_HOST} totara(\d)(\d)(|\.behat)(|\.localhost)(:[0-9]+)?$
25+ # Direct php requests to the php-X.X container.
26+ # Hostname format: [sitename.]totara{major}{minor}[.behat][.debug][.localhost]
27+ # Apply non-debug first, then override with debug if the host contains .debug.
28+ RewriteCond %{HTTP_HOST} totara(\d)(\d)(\.behat)?(\.localhost)?(:[0-9]+)?$
2729RewriteRule \.php - [H=proxy:fcgi://php-%1.%2:9000]
2830
29- # Direct xdebug requests to the php-X.X-debug container
30- RewriteCond %{HTTP_HOST} totara(\d)(\d)(| \.behat)\.debug(| \.localhost)(:[0-9]+)?$
31+ # Override: direct Xdebug requests to the php-X.X-debug container
32+ RewriteCond %{HTTP_HOST} totara(\d)(\d)(\.behat)? \.debug(\.localhost)? (:[0-9]+)?$
3133RewriteRule \.php - [H=proxy:fcgi://php-%1.%2-debug:9000]
3234
33- # Handle if the site name is specified in the host, e.g. sitename.totara73
34- RewriteCond %{HTTP_HOST} ^(.+)\.totara(|\.localhost)
35- RewriteRule ^(.*)$ - [E=SITENAME:%1]
35+ # Capture the optional sitename prefix from the hostname.
36+ # Matches: sitename.totara84, sitename.totara84.localhost, sitename.totara84.debug, etc.
37+ RewriteCond %{HTTP_HOST} ^([\w-]+)\.totara\d
38+ RewriteRule ^ - [E=SITENAME:%1]
3639
37- # If the server directory exists, then rewrite it to use it
40+ # v21+ (public/ directory exists): route all requests through the front controller.
41+ # The [H=proxy:...] flag is set here (not only for .php URLs) so that requests like /
42+ # or static-looking URLs are also processed by PHP-FPM via public/index.php.
43+ RewriteCond %{HTTP_HOST} totara(\d)(\d)
44+ RewriteCond %{HTTP_HOST} !\.debug
45+ RewriteCond %{DOCUMENT_ROOT}/%{ENV:SITENAME}/public/index.php -f
46+ RewriteRule ^ %{DOCUMENT_ROOT}/%{ENV:SITENAME}/public/index.php [QSA,L,H=proxy:fcgi://php-%1.%2:9000]
47+
48+ # v21+ (debug variant): same but routes to the debug PHP-FPM container
49+ RewriteCond %{HTTP_HOST} totara(\d)(\d).*\.debug
50+ RewriteCond %{DOCUMENT_ROOT}/%{ENV:SITENAME}/public/index.php -f
51+ RewriteRule ^ %{DOCUMENT_ROOT}/%{ENV:SITENAME}/public/index.php [QSA,L,H=proxy:fcgi://php-%1.%2-debug:9000]
52+
53+ # If the server directory exists (version 13 to 20), rewrite to use it
54+ RewriteCond %{DOCUMENT_ROOT}/%{ENV:SITENAME}/public/index.php !-f
3855RewriteCond %{DOCUMENT_ROOT}/%{ENV:SITENAME}/server/version.php -f
3956RewriteRule ^(.*)$ %{DOCUMENT_ROOT}/%{ENV:SITENAME}/server$1 [QSA]
4057
41- # Otherwise don't use the server directory
58+ # Otherwise (version 12 and older) don't use a subdirectory
59+ RewriteCond %{DOCUMENT_ROOT}/%{ENV:SITENAME}/public/index.php !-f
4260RewriteCond %{DOCUMENT_ROOT}/%{ENV:SITENAME}/server/version.php !-f
4361RewriteRule ^(.*)$ %{DOCUMENT_ROOT}/%{ENV:SITENAME}$1 [QSA]
4462
0 commit comments