1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
urlrewrite.php
См. документацию.
1<?php
2
5
6if (defined("BX_URLREWRITE"))
7{
8 return;
9}
10
11define("BX_URLREWRITE", true);
12
13error_reporting(E_COMPILE_ERROR | E_ERROR | E_CORE_ERROR | E_PARSE);
14
15require_once __DIR__ . "/../bx_root.php";
16require_once __DIR__ . "/../lib/loader.php";
17require_once __DIR__ . "/autoload.php";
18require_once __DIR__ . "/../tools.php";
19
20// try to fix REQUEST_URI under IIS
21$aProtocols = ['http', 'https'];
22foreach ($aProtocols as $prot)
23{
24 $marker = "404;" . $prot . "://";
25 if (($p = strpos($_SERVER["QUERY_STRING"], $marker)) !== false)
26 {
27 $uri = $_SERVER["QUERY_STRING"];
28 if (($p = strpos($uri, "/", $p + strlen($marker))) !== false)
29 {
30 if ($_SERVER["REQUEST_URI"] == '' || $_SERVER["REQUEST_URI"] == '/404.php' || str_contains($_SERVER["REQUEST_URI"], $marker))
31 {
32 $_SERVER["REQUEST_URI"] = substr($uri, $p);
33 }
34 $_SERVER["REDIRECT_STATUS"] = '404';
35 $_SERVER["QUERY_STRING"] = "";
36 $_GET = [];
37 break;
38 }
39 }
40}
41
42require_once $_SERVER["DOCUMENT_ROOT"] . getLocalPath('php_interface/dbconn.php', BX_PERSONAL_ROOT);
43
44$foundQMark = strpos($_SERVER["REQUEST_URI"], "?");
45$requestUriWithoutParams = ($foundQMark !== false ? substr($_SERVER["REQUEST_URI"], 0, $foundQMark) : $_SERVER["REQUEST_URI"]);
46$requestParams = ($foundQMark !== false ? substr($_SERVER["REQUEST_URI"], $foundQMark) : "");
47
48//decode only filename, not parameters
50
52
54
56if (file_exists($_SERVER['DOCUMENT_ROOT'] . "/urlrewrite.php"))
57{
58 include $_SERVER['DOCUMENT_ROOT'] . "/urlrewrite.php";
59}
60
61$uri = new Web\Uri($_SERVER["REQUEST_URI"]);
62if (!$uri->isPathTraversal())
63{
64 foreach ($arUrlRewrite as $val)
65 {
66 if (preg_match($val["CONDITION"], $requestUri))
67 {
68 if (!empty($val["RULE"]))
69 {
70 $url = preg_replace($val["CONDITION"], ($val["PATH"] <> '' ? $val["PATH"] . "?" : "") . $val["RULE"], $requestUri);
71 }
72 else
73 {
74 $url = $val["PATH"];
75 }
76
77 if (($pos = strpos($url, "?")) !== false)
78 {
79 $params = substr($url, $pos + 1);
80 parse_str($params, $vars);
81
82 $_GET += $vars;
83 $_REQUEST += $vars;
84 $_SERVER["QUERY_STRING"] = Web\Uri::urnEncode($params, false);
85 $url = substr($url, 0, $pos);
86
87 // actualize context if it is initialized already
88 Context::getCurrent()?->getRequest()->modifyByQueryString($_SERVER["QUERY_STRING"]);
89 }
90
92
93 if (!$io->FileExists($_SERVER['DOCUMENT_ROOT'] . $url))
94 {
95 continue;
96 }
97
98 if (!$io->ValidatePathString($url))
99 {
100 continue;
101 }
102
103 $urlTmp = strtolower(ltrim($url, "/\\"));
104 $urlTmp = str_replace(".", "", $urlTmp);
105
106 if ((str_starts_with($urlTmp, "upload/") || (str_starts_with($urlTmp, "bitrix/") && !str_starts_with($urlTmp, "bitrix/services/") && !str_starts_with($urlTmp, "bitrix/groupdavphp"))))
107 {
108 continue;
109 }
110
111 $ext = strtolower(GetFileExtension($url));
112 if ($ext != "php")
113 {
114 continue;
115 }
116
117 // D7 response is not available here
118 if (stristr(php_sapi_name(), "cgi") !== false && (!defined("BX_HTTP_STATUS") || !BX_HTTP_STATUS))
119 {
120 header("Status: 200 OK");
121 }
122 else
123 {
124 header($_SERVER["SERVER_PROTOCOL"] . " 200 OK");
125 }
126
127 $_SERVER["REAL_FILE_PATH"] = $url;
128 include_once $io->GetPhysicalName($_SERVER['DOCUMENT_ROOT'] . $url);
129 die();
130 }
131 }
132}
133
134//admin section 404
135if (str_starts_with($requestUri, "/bitrix/admin/"))
136{
137 $_SERVER["REAL_FILE_PATH"] = "/bitrix/admin/404.php";
138 include $_SERVER["DOCUMENT_ROOT"] . "/bitrix/admin/404.php";
139 die();
140}
141
142define("BX_CHECK_SHORT_URI", true);
Определения uri.php:17
static urnEncode($str, $charset='UTF-8')
Определения uri.php:416
static GetInstance()
Определения virtual_io.php:60
$_REQUEST["admin_mnu_menu_id"]
Определения get_menu.php:8
$p
Определения group_list_element_edit.php:23
$_SERVER["DOCUMENT_ROOT"]
Определения cron_frame.php:9
$io
Определения csv_new_run.php:98
$requestUriWithoutParams
Определения urlrewrite.php:45
if(file_exists($_SERVER['DOCUMENT_ROOT'] . "/urlrewrite.php")) $uri
Определения urlrewrite.php:61
$aProtocols
Определения urlrewrite.php:21
$requestUri
Определения urlrewrite.php:51
$requestParams
Определения urlrewrite.php:46
$foundQMark
Определения urlrewrite.php:44
$requestPage
Определения urlrewrite.php:49
$arUrlRewrite
Определения urlrewrite.php:55
GetFileExtension($path)
Определения tools.php:2972
getLocalPath($path, $baseFolder="/bitrix")
Определения tools.php:5092
_normalizePath($strPath)
Определения tools.php:3341
Определения culture.php:9
Определения cookie.php:3
die
Определения quickway.php:367
if($inWords) echo htmlspecialcharsbx(Number2Word_Rus(roundEx($totalVatSum $params['CURRENCY']
Определения template.php:799
$val
Определения options.php:1793
$url
Определения iframe.php:7