A
A
adun32018-07-18 14:58:48
1C-Bitrix
adun3, 2018-07-18 14:58:48

How to change request_uri in Bitrix?

You need to implement SEO URLs.
I used to just replace the $_SERVER['REQUEST_URI'] variable in init.php, now it doesn't work. How to make a substitution in d7?
update.
All links that I want to change are made by the smart filter. Which removes all get parameters i.e. urlrewrite.php just can't be substituted. Is it really necessary to rewrite the smart filter...

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Emelyanov, 2018-07-19
@babarun

As xzdshr already wrote , this cannot be done, but let's figure out where it is located in d7.
First, let's find out how in general you can get a URI in d7:

use Bitrix\Main\Application; 
use Bitrix\Main\Web\Uri; 
$request = Application::getInstance()->getContext()->getRequest(); 
$requestUri= $request->getRequestUri();

Let's take a look at the implementation of this method, maybe there is a setRequestUri nearby?
//    HttpRequest::getRequestUri()
//    /bitrix/modules/main/lib/httprequest.php:226

    public function getRequestUri()
    {
        return $this->server->getRequestUri();
    }

Yeah, HttpRequest is inherited from Request'a And that, being an abstract class, in turn extends ParameterDictionary
And then we go down to the class implementation Dictionary, where we will be interested in the offsetSet method:
/**
   * Offset to set
   */
  public function offsetSet($offset, $value)
  {
    if($offset === null)
    {
      $this->values[] = $value;
    }
    else
    {
      $this->values[$offset] = $value;
    }
  }

Which we will try to use:
<?
use Bitrix\Main\Application;
use Bitrix\Main\Web\Uri;
$request = Application::getInstance()->getContext()->getRequest();
$request->offsetSet("REQUEST_URI", 'abrakadabra.php');

And we get:
[Bitrix\Main\NotSupportedException] 
Can not set readonly value (150)
/home/bitrix/www/bitrix/modules/main/lib/type/parameterdictionary.php:53
#0: Bitrix\Main\Type\ParameterDictionary->offsetSet(string, string)

Because there is a wonderful method in the parameterdictionary.php file on line 51:
/**
   * Offset to set
   */
  public function offsetSet($offset, $value)
  {
    throw new NotSupportedException("Can not set readonly value");
  }

Moral, if you want to correct this injustice, then you have to climb deep enough.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question