What is the magento 2 equivalent of $_SERVER['QUERY_STRING']

I want to retrieve the full query string from the url and would like to do this using the framework's built in functions.


1 Answer 1


I was able to achieve this using the getServer() in the \Magento\Framework\HTTP\PhpEnvironment\Request class

public function __construct
    \Magento\Framework\HTTP\PhpEnvironment\Request $request,
    $this->request = $request;

public function execute()

If no argument is set, $this->request->getServer() will return complete $_SERVER array

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.