# Get full url to a product and to a product image

**URL:** <https://forum.shopware.com/t/get-full-url-to-a-product-and-to-a-product-image/39099>\
**Category:** International (English Only)\
**Tags:** programming\
**Created:** [16. August 2016 um 10:05 UTC](https://forum.shopware.com/t/get-full-url-to-a-product-and-to-a-product-image/39099 "2016-08-16T10:05:12Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![PieterSition](https://avatars.discourse-cdn.com/v4/letter/p/a87d85/32.png) [@PieterSition](https://forum.shopware.com/u/PieterSition)\
**Post date:** [16. August 2016 um 10:05 UTC](https://forum.shopware.com/t/get-full-url-to-a-product-and-to-a-product-image/39099/1 "2016-08-16T10:05:12Z")

</div>

I’m creating a Shopware plugin to create a xml feed.  
In this xml feed I want to put all articles, with for every article an url to the article + an url to the image.  
I have found an url to both, but both gets redirected to another url.

I want to find the url Shopware is redirecting to.  
I’m currently using the following code to do it.

But making a curl call to get the url being redirected to is taking a lot of time, and Shopware knows what the correct url is.

So how can I directly access the url Shopware redirects to?

(article param is an Article/Article model)

```
	/**
	 * Build the url to an article
	 * @return string Url to article
	 */
	public function getUrlForArticle($article)
	{
		$articleId = $article->getId();

		$host = Shopware()->Config()->get("host");

		$db = Shopware()->Db();

		$sql = "SELECT path FROM s_core_rewrite_urls WHERE org_path = :org_path";
		$params = [":org_path" => "sViewport=detail&sArticle={$articleId}"];

		$query = $db->executeQuery($sql, $params);
		$row = $query->fetch();

		return isset($row['path']) ? "http://{$host}/{$row['path']}" : "";
	}

	public function getImageurlForArticle($article)
	{
		// engine/Shopware/Controllers/Frontend/Detail.php on line 99 (sGetArticleById)
		// engine/Shopware/Components/Compatibility/LegacyStructConverter.php on line 375 (convertMediaStruct)
		
		$image = $article->getImages()->first();

		if( $image )
		{
			$media = $image->getMedia();

			$host = Shopware()->Config()->get("host");

			$path = $media->getPath();

			// dont follow urls, takes a looooong time
			// return $this->getUrlRedirectedTo("http://{$host}/{$path}");
			
			return "http://{$host}/{$path}";
		}

        return "";
	}

	/**
	 * Get url redirected to for an url
	 * @param string $url Url to follow redirects
	 * @return string Url redirected to
	 */
	public function getUrlRedirectedTo($url)
	{
		// http://stackoverflow.com/a/21032909/2492536
		
	    $ch = curl_init();
	    curl_setopt($ch, CURLOPT_URL, $url); // set url
	    curl_setopt($ch, CURLOPT_HEADER, true); // get header
	    curl_setopt($ch, CURLOPT_NOBODY, true); // do not include response body
	    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // do not show in browser the response
	    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); // follow any redirects
	    curl_exec($ch);
	    $newUrl = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL); //extract the url from the header response
	    curl_close($ch);

	    return $newUrl;
	}

```

&nbsp;
