diff --git a/.gitignore b/.gitignore index f58804377988104a051f1c6181da09e0fdbf48c9..e113ca79ddcdfb35a2f265bcfb26db9ed79b3532 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ .htaccess +.htaccess-subsite-map.txt sites/sites.php sites/*/ !sites/all/ diff --git a/.htaccess-subsite-map.txt.sample b/.htaccess-subsite-map.txt.sample new file mode 100644 index 0000000000000000000000000000000000000000..0234f59895db17a34007534b598993701c8c6ece --- /dev/null +++ b/.htaccess-subsite-map.txt.sample @@ -0,0 +1,5 @@ +# This file is automatically generated. +# Do not edit it unless you know what you are doing! + +# %UNL_CREATION_TOOL_STUB% + diff --git a/.htaccess.sample b/.htaccess.sample index db1427b9317a0f0480076a10c77b16463b1c9bec..6d5bf017531b5f65e4077b161db20a99ef835033 100644 --- a/.htaccess.sample +++ b/.htaccess.sample @@ -56,16 +56,23 @@ DirectoryIndex index.php index.html index.htm <IfModule mod_rewrite.c> RewriteEngine on - # THIS SECTION IS AUTOMATICALY GENERATED. + # THIS SECTION IS FOR UNL SUBSITES # DO NOT EDIT!!!! - + + # Add the following line to your httpd.conf + # RewriteMap drupal_subsites txt:<DRUPAL_ROOT>/.htaccess-subsite-map.txt + # Do not uncomment the previous line. + RewriteRule .*/cron.php cron.php RewriteRule .*/update.php update.php - - # %UNL_CREATION_TOOL_STUB% - - # END AUTOMATICALLY GENERATED AREA. - + RewriteRule ^(.*?/(misc|modules|sites|themes))(.*) ${drupal_subsites:$1|$1}$3 + + RewriteCond ${drupal_subsites://%{HTTP_HOST}%{REQUEST_URI}|NOT_FOUND} !^NOT_FOUND$ + RewriteRule (.*) ${drupal_subsites://%{HTTP_HOST}%{REQUEST_URI}|$1} [R,L] + + # END SUBSITE AREA. + + # Block access to "hidden" directories whose names begin with a period. This # includes directories used by version control systems such as Subversion or # Git to store control files. Files whose names begin with a period, as well diff --git a/sites/all/modules/unl_multisite/cron.php b/sites/all/modules/unl_multisite/cron.php old mode 100644 new mode 100755 index 5acf21e94f785c3641325e8bc9b9e0b2e470458e..2d024f186e7a0239d251e35741a2a9c212d74f45 --- a/sites/all/modules/unl_multisite/cron.php +++ b/sites/all/modules/unl_multisite/cron.php @@ -393,24 +393,24 @@ function unl_add_site_to_htaccess($site_id, $site_path, $is_alias) { $site_path .= '/'; } - unl_require_writable(DRUPAL_ROOT . '/.htaccess'); + unl_require_writable(DRUPAL_ROOT . '/.htaccess-subsite-map.txt'); - $stub_token = ' # %UNL_CREATION_TOOL_STUB%'; - $htaccess = file_get_contents(DRUPAL_ROOT . '/.htaccess'); + $stub_token = '# %UNL_CREATION_TOOL_STUB%'; + $htaccess = file_get_contents(DRUPAL_ROOT . '/.htaccess-subsite-map.txt'); $stub_pos = strpos($htaccess, $stub_token); if ($stub_pos === FALSE) { - throw new Exception('Unable to find stub site entry in .htaccess.'); + throw new Exception('Unable to find stub site entry in .htaccess-subsite-map.txt.'); } $new_htaccess = substr($htaccess, 0, $stub_pos) - . " # %UNL_START_{$site_or_alias}_ID_{$site_id}%\n"; + . "# %UNL_START_{$site_or_alias}_ID_{$site_id}%\n"; foreach (array('misc', 'modules', 'sites', 'themes') as $drupal_dir) { - $new_htaccess .= " RewriteRule $site_path$drupal_dir/(.*) $drupal_dir/$1\n"; + $new_htaccess .= "$site_path$drupal_dir $drupal_dir\n"; } - $new_htaccess .= " # %UNL_END_{$site_or_alias}_ID_{$site_id}%\n\n" + $new_htaccess .= "# %UNL_END_{$site_or_alias}_ID_{$site_id}%\n\n" . $stub_token . substr($htaccess, $stub_pos + strlen($stub_token)); - _unl_file_put_contents_atomic(DRUPAL_ROOT . '/.htaccess', $new_htaccess); + _unl_file_put_contents_atomic(DRUPAL_ROOT . '/.htaccess-subsite-map.txt', $new_htaccess); } function unl_remove_site_from_htaccess($site_id, $is_alias) { @@ -421,11 +421,11 @@ function unl_remove_site_from_htaccess($site_id, $is_alias) { $site_or_alias = 'SITE'; } - unl_require_writable(DRUPAL_ROOT . '/.htaccess'); + unl_require_writable(DRUPAL_ROOT . '/.htaccess-subsite-map.txt'); - $htaccess = file_get_contents(DRUPAL_ROOT . '/.htaccess'); - $site_start_token = "\n # %UNL_START_{$site_or_alias}_ID_{$site_id}%"; - $site_end_token = " # %UNL_END_{$site_or_alias}_ID_{$site_id}%\n"; + $htaccess = file_get_contents(DRUPAL_ROOT . '/.htaccess-subsite-map.txt'); + $site_start_token = "\n# %UNL_START_{$site_or_alias}_ID_{$site_id}%"; + $site_end_token = "# %UNL_END_{$site_or_alias}_ID_{$site_id}%\n"; $start_pos = strpos($htaccess, $site_start_token); $end_pos = strpos($htaccess, $site_end_token); @@ -437,36 +437,34 @@ function unl_remove_site_from_htaccess($site_id, $is_alias) { $new_htaccess = substr($htaccess, 0, $start_pos) . substr($htaccess, $end_pos + strlen($site_end_token)) ; - _unl_file_put_contents_atomic(DRUPAL_ROOT . '/.htaccess', $new_htaccess); + _unl_file_put_contents_atomic(DRUPAL_ROOT . '/.htaccess-subsite-map.txt', $new_htaccess); } function unl_add_page_alias_to_htaccess($site_id, $host, $path, $to_uri) { - unl_require_writable(DRUPAL_ROOT . '/.htaccess'); + unl_require_writable(DRUPAL_ROOT . '/.htaccess-subsite-map.txt'); - $stub_token = ' # %UNL_CREATION_TOOL_STUB%'; - $htaccess = file_get_contents(DRUPAL_ROOT . '/.htaccess'); + $stub_token = '# %UNL_CREATION_TOOL_STUB%'; + $htaccess = file_get_contents(DRUPAL_ROOT . '/.htaccess-subsite-map.txt'); $stub_pos = strpos($htaccess, $stub_token); if ($stub_pos === FALSE) { - throw new Exception('Unable to find stub page alias entry in .htaccess.'); + throw new Exception('Unable to find stub page alias entry in .htaccess-subsite-map.txt.'); } $new_htaccess = substr($htaccess, 0, $stub_pos) - . " # %UNL_START_PAGE_ALIAS_ID_{$site_id}%\n" - . " RewriteCond %{HTTP_HOST} ^{$host}$\n" - . " RewriteCond %{REQUEST_URI} ^{$path}$\n" - . " RewriteRule (.*) {$to_uri} [R,L]\n" - . " # %UNL_END_PAGE_ALIAS_ID_{$site_id}%\n\n" + . "# %UNL_START_PAGE_ALIAS_ID_{$site_id}%\n" + . "//$host$path $to_uri\n" + . "# %UNL_END_PAGE_ALIAS_ID_{$site_id}%\n\n" . $stub_token . substr($htaccess, $stub_pos + strlen($stub_token)); - _unl_file_put_contents_atomic(DRUPAL_ROOT . '/.htaccess', $new_htaccess); + _unl_file_put_contents_atomic(DRUPAL_ROOT . '/.htaccess-subsite-map.txt', $new_htaccess); } function unl_remove_page_alias_from_htaccess($site_id) { - unl_require_writable(DRUPAL_ROOT . '/.htaccess'); + unl_require_writable(DRUPAL_ROOT . '/.htaccess-subsite-map.txt'); - $htaccess = file_get_contents(DRUPAL_ROOT . '/.htaccess'); - $site_start_token = "\n # %UNL_START_PAGE_ALIAS_ID_{$site_id}%"; - $site_end_token = " # %UNL_END_PAGE_ALIAS_ID_{$site_id}%\n"; + $htaccess = file_get_contents(DRUPAL_ROOT . '/.htaccess-subsite-map.txt'); + $site_start_token = "\n# %UNL_START_PAGE_ALIAS_ID_{$site_id}%"; + $site_end_token = "# %UNL_END_PAGE_ALIAS_ID_{$site_id}%\n"; $start_pos = strpos($htaccess, $site_start_token); $end_pos = strpos($htaccess, $site_end_token); @@ -478,7 +476,7 @@ function unl_remove_page_alias_from_htaccess($site_id) { $new_htaccess = substr($htaccess, 0, $start_pos) . substr($htaccess, $end_pos + strlen($site_end_token)) ; - _unl_file_put_contents_atomic(DRUPAL_ROOT . '/.htaccess', $new_htaccess); + _unl_file_put_contents_atomic(DRUPAL_ROOT . '/.htaccess-subsite-map.txt', $new_htaccess); } function unl_add_alias_to_sites_php($alias_site_dir, $real_site_dir, $alias_id) {