0

I was wondering if somebody might have a solution for me. Currently I have a working IndexController which brings back the correct sku from a search.

However the problem is that once the rewrite is made it adds the complete URL which does not link to a product page.

    // Check we have a product.
    if ($product->getId()) {
        // Get the URL and redirect to it.
        $url = $product->getProductUrl();
        if ($url) {
            $this->_redirectUrl('/support/'.$url);
            return true;
        }

    }
    // If we didn't find a matching product, load the default.
    $this->loadNoRoute();
    return false;

It then proceeds to load a URL like this: https://mywebiteurl/support/https://mywebsiteurl/macbook-pro.html

Where I require the URL to load like this: https://mywebiteurl/support/macbook-pro.html

Wondering if anybody could point me in the right direction as I'm going round in circles. Any help would be appreciated.

Thanks.

1 Answer 1

0

You can get partial url ( without domain name ) using this code snipt :

$request = parse_url($url);

your code will be like this :

// Check we have a product.
if ($product->getId()) {
    // Get the URL and redirect to it.
    $url = $product->getProductUrl();

    // Parse URL
    $request = parse_url($url); 
    $pageUrl = $request['path']; // Get URL without domain name

    if ($url) {
        $this->_redirectUrl('/support/'.$pageUrl);
        return true;
    }

}
// If we didn't find a matching product, load the default.
$this->loadNoRoute();
return false;

hope it will help, or you can use that logic to implement your desired functionality.

Your Answer

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

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