Last active
June 4, 2016 00:21
-
-
Save gapple/9e91d3e19604eb6d9e33dcf955bbcd9c to your computer and use it in GitHub Desktop.
Drupal multilingual multi-site in a sub-path
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Trick Drupal into thinking it's being run from a sub-folder. | |
// @see conf_path() | |
if (preg_match('<^/([\w]+-subpath)>', $_SERVER['REQUEST_URI'], $url_subpath_match)) { | |
$_SERVER['SCRIPT_NAME'] = '/' . $url_subpath_match[1] ./' . $_SERVER['SCRIPT_NAME']; | |
} | |
else if (preg_match('<^/(sites/subsite/files/styles)>', $_SERVER['REQUEST_URI'])) { | |
// Direct image style requests to the subsite | |
$_SERVER['SCRIPT_NAME'] = '/en-subpath' . $_SERVER['SCRIPT_NAME']; | |
$_SERVER['REQUEST_URI'] = '/en-subpath' . $_SERVER['REQUEST_URI']; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/redirect.module b/redirect.module | |
index a503159..4658090 100644 | |
--- a/redirect.module | |
+++ b/redirect.module | |
@@ -1122,7 +1122,7 @@ function redirect_can_redirect() { | |
$path = current_path(); | |
$can_redirect = TRUE; | |
- if ($_SERVER['SCRIPT_NAME'] != $GLOBALS['base_path'] . 'index.php') { | |
+ if ($_SERVER['SCRIPT_NAME'] != $GLOBALS['base_path'] . 'index.php' && is_file($_SERVER['SCRIPT_NAME'])) { | |
// Do not redirect if the root script is not /index.php. | |
$can_redirect = FALSE; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Since we're tricking Drupal into thinking it's being run from a subpath in | |
// index.php, we need to fix the $base_url, so that static assets (e.g. module | |
// and theme js and css files) are loaded without any prefix. | |
// Later, the custom language handler prefixes internal paths with the subpath | |
// where required. (@see MYMODULE_subpath_language_rewrite_url()) | |
$base_url = | |
(isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on' ? 'https' : 'http') . | |
'://' . | |
$_SERVER['HTTP_HOST']; | |
// Determine cookie domain, because we can't rely on Drupal's default behaviour. | |
// @see drupal_settings_initialize() | |
$cookie_domain = $_SERVER['HTTP_HOST']; | |
// Strip leading periods, www., and port numbers from cookie domain. | |
$cookie_domain = ltrim($cookie_domain, '.'); | |
if (strpos($cookie_domain, 'www.') === 0) { | |
$cookie_domain = substr($cookie_domain, 4); | |
} | |
$cookie_domain = explode(':', $cookie_domain); | |
$cookie_domain = '.' . $cookie_domain[0]; | |
if (preg_match('<^/([\w]+-subpath)>', $_SERVER['REQUEST_URI'], $url_subpath_match)) { | |
$cookie_path = '/' . $url_subpath_match[1] . '/'; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$sites['example.com.en-subpath'] = 'subsite'; | |
$sites['dev.example.com.en-subpath'] = 'subsite'; | |
$sites['example.com.fr-subpath'] = 'subsite'; | |
$sites['dev.example.com.fr-subpath'] = 'subsite'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment