2

I want to get URL like this after domain URL

domainname/hellowword/example-index

2 Answers 2

1

Try This code

protected $_storeManager;

public function __construct(
    ..........................................................
    \Magento\Store\Model\StoreManagerInterface $storeManager,
    ..........................................................
) {
    ..........................................................
    $this->_storeManager = $storeManager;
    ..........................................................
}

public function getCustomiseUrl()
{
    $url = $this->_storeManager->getStore()->getUrl('hellowword/example-index');
    //$url = $this->_storeManager->getStore()->getCurrentUrl();
    // get prase url
    $prse_url = parse_url($url);
    $get_url = '';
    if (isset($prse_url['host'])) {
        $get_url = $prse_url['host'];
    }
    if (isset($prse_url['path'])) {
        $get_url .= $prse_url['path'];
    }
    echo "get_url ".$get_url;
}

I Hope This Helps You.

0
1

You can try to create a custom router (https://devdocs.magento.com/guides/v2.4/extension-dev-guide/routing.html)

or create a URL redirect from the admin URL rewrites to point your hellowword/example-index to your action controller (https://docs.magento.com/user-guide/marketing/url-rewrite-custom.html)

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.