diff --git a/.htaccess b/.htaccess index ae3580590..71d1f48ee 100644 --- a/.htaccess +++ b/.htaccess @@ -13,32 +13,7 @@ RewriteRule ^(.+)/(addons|files|layouts|m\.layouts|modules|widgets|widgetstyles) RewriteCond %{SCRIPT_FILENAME} !-f RewriteRule ^(.+)\.min\.(css|js)$ ./$1.$2 [L] -# rss, blogAPI -RewriteRule ^(rss|atom)$ ./index.php?module=rss&act=$1 [L] -RewriteRule ^([a-zA-Z0-9_]+)/(rss|atom|api)$ ./index.php?mid=$1&act=$2 [L] - -# trackback -RewriteRule ^([0-9]+)/(.+)/trackback$ ./index.php?document_srl=$1&key=$2&act=trackback [L] -RewriteRule ^([a-zA-Z0-9_]+)/([0-9]+)/(.+)/trackback$ ./index.php?mid=$1&document_srl=$2&key=$3&act=trackback [L] - -# document category -RewriteRule ^([a-zA-Z0-9_]+)/category/([0-9]+)$ ./index.php?mid=$1&category=$2 [L,QSA] - -# document permanent link -RewriteRule ^([0-9]+)$ ./index.php?document_srl=$1 [L,QSA] - -# admin module link -RewriteRule ^admin/?$ ./index.php?module=admin [L,QSA] - -# mid link +# all other short URLs +RewriteCond %{SCRIPT_FILENAME} !-f RewriteCond %{SCRIPT_FILENAME} !-d -RewriteRule ^([a-zA-Z0-9_]+)/?$ ./index.php?mid=$1 [L,QSA] - -# mid + document link -RewriteRule ^([a-zA-Z0-9_]+)/([0-9]+)$ ./index.php?mid=$1&document_srl=$2 [L,QSA] - -# mid + entry title -RewriteRule ^([a-zA-Z0-9_]+)/entry/(.+)$ ./index.php?mid=$1&entry=$2 [L,QSA] - -# file download -RewriteRule ^files/download/([0-9]+)/([a-zA-Z0-9_-]+)/(.+)$ ./index.php?act=procFileOutput&file_srl=$1&file_key=$2&filename=$3 [L] +RewriteRule . index.php [L] diff --git a/classes/context/Context.class.php b/classes/context/Context.class.php index 02930c18f..e041f89b9 100644 --- a/classes/context/Context.class.php +++ b/classes/context/Context.class.php @@ -249,7 +249,7 @@ class Context // Set information about the current request. self::_checkGlobalVars(); self::setRequestMethod(); - self::setRequestArguments(); + self::setRequestArguments(Rhymix\Framework\Router::getRequestArguments()); self::setUploadInfo(); // Load system configuration. @@ -1185,9 +1185,9 @@ class Context * * @return void */ - public static function setRequestArguments() + public static function setRequestArguments($router_args = []) { - foreach($_REQUEST as $key => $val) + foreach($router_args ?: $_REQUEST as $key => $val) { if($val === '' || isset(self::$_reserved_keys[$key]) || self::get($key)) { @@ -1211,7 +1211,7 @@ class Context } // Set deprecated request parameters. - if(!$_POST && !empty($GLOBALS['HTTP_RAW_POST_DATA'])) + if($_SERVER['REQUEST_METHOD'] === 'POST' && !$_POST && !empty($GLOBALS['HTTP_RAW_POST_DATA'])) { if(self::getRequestMethod() === 'XMLRPC') { @@ -1231,6 +1231,10 @@ class Context foreach((array)$params as $key => $val) { + if (isset($router_args[$key])) + { + continue; + } $key = escape($key); $val = self::_filterXmlVars($key, $val); self::set($key, $val, true); @@ -1242,6 +1246,10 @@ class Context parse_str($GLOBALS['HTTP_RAW_POST_DATA'], $params); foreach($params as $key => $val) { + if (isset($router_args[$key])) + { + continue; + } $key = escape($key); $val = self::_filterRequestVar($key, $val); self::set($key, $val, true); diff --git a/common/framework/router.php b/common/framework/router.php index 8449d0c13..39138332e 100644 --- a/common/framework/router.php +++ b/common/framework/router.php @@ -7,6 +7,21 @@ namespace Rhymix\Framework; */ class Router { + /** + * List of XE-compatible rewrite rules. + */ + protected static $_xe_compatible_rules = array( + 'admin' => ['module' => 'admin'], + '(?rss|atom)' => [], + '(?[0-9]+)' => [], + '(?[a-zA-Z0-9_-]+)/?' => [], + '(?[a-zA-Z0-9_-]+)/(?[0-9]+)' => [], + '(?[a-zA-Z0-9_-]+)/category/(?[0-9]+)' => [], + '(?[a-zA-Z0-9_-]+)/entry/(?[^/]+)' => [], + '(?[a-zA-Z0-9_-]+)/(?rss|atom|api)' => [], + 'files/download/(?[0-9]+)/(?[a-zA-Z0-9_-]+)/(?[^/]+)' => ['act' => 'procFileOutput'], + ); + /** * Return the currently configured rewrite level. * @@ -25,4 +40,49 @@ class Router } return intval($level); } + + /** + * Extract request arguments from the current URL. + * + * @return array + */ + public static function getRequestArguments(): array + { + // Get the local part of the current URL. + $url = $_SERVER['REQUEST_URI']; + if (starts_with(\RX_BASEURL, $url)) + { + $url = substr($url, strlen(\RX_BASEURL)); + } + + // Separate additional arguments from the URL. + $args = array(); + $argstart = strpos($url, '?'); + if ($argstart !== false) + { + @parse_str(substr($url, $argstart + 1), $args); + $url = substr($url, 0, $argstart); + } + + // Decode the URL into plain UTF-8. + $url = urldecode($url); + if ($url === '' || (function_exists('mb_check_encoding') && !mb_check_encoding($url, 'UTF-8'))) + { + return array(); + } + + // Try XE-compatible rules. + foreach (self::$_xe_compatible_rules as $regexp => $additional_args) + { + if (preg_match('#^' . $regexp . '$#', $url, $matches)) + { + $matches = array_filter($matches, 'is_string', \ARRAY_FILTER_USE_KEY); + $allargs = array_merge($additional_args ?: [], $matches, $args ?: []); + return $allargs; + } + } + + // If no pattern matches, return an empty array. + return array(); + } } diff --git a/common/manual/server_config/rhymix-nginx-subdir.conf b/common/manual/server_config/rhymix-nginx-subdir.conf index 69b8ef0df..06d370827 100644 --- a/common/manual/server_config/rhymix-nginx-subdir.conf +++ b/common/manual/server_config/rhymix-nginx-subdir.conf @@ -25,33 +25,7 @@ location ~ ^/rhymix/(.+)\.min\.(css|js)$ { try_files $uri $uri/ /rhymix/$1.$2; } -# rss, blogAPI -rewrite ^/rhymix/(rss|atom)$ /rhymix/index.php?module=rss&act=$1 last; -rewrite ^/rhymix/([a-zA-Z0-9_]+)/(rss|atom|api)$ /rhymix/index.php?mid=$1&act=$2 last; - -# trackback -rewrite ^/rhymix/([0-9]+)/(.+)/trackback$ /rhymix/index.php?document_srl=$1&key=$2&act=trackback last; -rewrite ^/rhymix/([a-zA-Z0-9_]+)/([0-9]+)/(.+)/trackback$ /rhymix/index.php?mid=$1&document_srl=$2&key=$3&act=trackback last; - -# administrator page -rewrite ^/rhymix/admin/?$ /rhymix/index.php?module=admin last; - -# document category -rewrite ^/rhymix/([a-zA-Z0-9_]+)/category/([0-9]+)$ /rhymix/index.php?mid=$1&category=$2 last; - -# document permanent link -rewrite ^/rhymix/([0-9]+)$ /rhymix/index.php?document_srl=$1 last; - -# mid link -location ~ ^/rhymix/([a-zA-Z0-9_]+)/?$ { - try_files $uri $uri/ /rhymix/index.php?mid=$1; +# all other short URLs +location /rhymix/ { + try_files $uri $uri/ /rhymix/index.php$is_args$args; } - -# mid + document link -rewrite ^/rhymix/([a-zA-Z0-9_]+)/([0-9]+)$ /rhymix/index.php?mid=$1&document_srl=$2 last; - -# mid + entry title -rewrite ^/rhymix/([a-zA-Z0-9_]+)/entry/(.+)$ /rhymix/index.php?mid=$1&entry=$2 last; - -# file download -rewrite ^/rhymix/files/download/([0-9]+)/([a-zA-Z0-9_-]+)/(.+)$ /rhymix/index.php?act=procFileOutput&file_srl=$1&file_key=$2&filename=$3 last; diff --git a/common/manual/server_config/rhymix-nginx.conf b/common/manual/server_config/rhymix-nginx.conf index 11aed6f3f..04306e0bd 100644 --- a/common/manual/server_config/rhymix-nginx.conf +++ b/common/manual/server_config/rhymix-nginx.conf @@ -25,33 +25,7 @@ location ~ ^/(.+)\.min\.(css|js)$ { try_files $uri $uri/ /$1.$2; } -# rss, blogAPI -rewrite ^/(rss|atom)$ /index.php?module=rss&act=$1 last; -rewrite ^/([a-zA-Z0-9_]+)/(rss|atom|api)$ /index.php?mid=$1&act=$2 last; - -# trackback -rewrite ^/([0-9]+)/(.+)/trackback$ /index.php?document_srl=$1&key=$2&act=trackback last; -rewrite ^/([a-zA-Z0-9_]+)/([0-9]+)/(.+)/trackback$ /index.php?mid=$1&document_srl=$2&key=$3&act=trackback last; - -# administrator page -rewrite ^/admin/?$ /index.php?module=admin last; - -# document category -rewrite ^/([a-zA-Z0-9_]+)/category/([0-9]+)$ /index.php?mid=$1&category=$2 last; - -# document permanent link -rewrite ^/([0-9]+)$ /index.php?document_srl=$1 last; - -# mid link -location ~ ^/([a-zA-Z0-9_]+)/?$ { - try_files $uri $uri/ /index.php?mid=$1; +# all other short URLs +location / { + try_files $uri $uri/ /index.php$is_args$args; } - -# mid + document link -rewrite ^/([a-zA-Z0-9_]+)/([0-9]+)$ /index.php?mid=$1&document_srl=$2 last; - -# mid + entry title -rewrite ^/([a-zA-Z0-9_]+)/entry/(.+)$ /index.php?mid=$1&entry=$2 last; - -# file download -rewrite ^/files/download/([0-9]+)/([a-zA-Z0-9_-]+)/(.+)$ /index.php?act=procFileOutput&file_srl=$1&file_key=$2&filename=$3 last;