How can I access the original URL segment in PHP before Cornerstone processes the page?

Hi there,

I’m trying to access the first part of the URL path via PHP, for example:
example.com/en/article-title/ → I want to get "en" as a language or path segment.

I’ve tried using $_SERVER['REQUEST_URI'] , REDIRECT_URL , SCRIPT_NAME , and others – inside hooks like template_redirect and wp_head . But by the time these run, the URL appears to have been rewritten (possibly by Cornerstone or another system), and I only get / or the internal path.

I need to capture this information early during page load (ideally before <head> is rendered), and I can’t rely on JavaScript or cookies – this must work for both users and crawlers (server-side only).

Is there a recommended way in Pro/Cornerstone to access the original request path or first URL segment before Cornerstone has fully processed the page?

Thanks a lot!

Hello @johanlundgren,

Thank you for the inquiry.

We may need to see where you’re testing this to better understand what you’re trying to do. If you need to retrieve the full URL, you can try this code:

add_action('template_redirect', function () {
    $url = home_url(add_query_arg(null, null));
    echo '<pre>' . var_export($url, true) . '</pre>';
}, 10);

You can then process the result to extract only the part or path you’re trying to retrieve. Let us know the result.

Best regards.