As the title says, content is being returned correctly but the status code is 404
.
I have checked the .htaccess file and the Apache config file as well. All seems to be fine.
I have the following in my module routing file:
my_module.news_list:
path: /api/{state}/news
defaults:
_controller: Drupal\my_module\Controller\NewsController::index
methods: [GET]
requirements:
_access: 'TRUE'
This is the function that does the redirect in my EventSubscriber
public function redirectRequestToModule(GetResponseEvent $event) {
$request = $event->getRequest();
$validPathBegins = ['/men', '/nat'];
// This is necessary because this also gets called on
// node sub-tabs such as "edit", "revisions", etc. This
// prevents those pages from being redirected.
$requestUri = $request->getRequestUri();
if (!in_array(substr($requestUri, 0, 4), $validPathBegins)) {
return;
}
$node = $request->attributes->get('node');
// get the configured request query parameters for this content type
$redirect_url = '/api' . $requestUri;
$kernel = $event->getKernel();
$response = $kernel->handle(Request::create($redirect_url));
$event->setResponse($response);
}
This is what I type in the browser: mysite.com/nat/news/
The content returned is correct but the status code is 404
.
P.S There isn't a reachable path on my Drupal website like /nat/news
. The path mentioned is supposed to return a list of news articles.
/nat/news
to an internal path matching a route./admin/config/search/path/add
worked. I created an alias/api/nat/news/
to/nat/news