Posted on

Magento 2 Check if url returns 404

I have ann Array of urls

$arr = Array(
‘http://magento2.com/url-exist’,
‘http://magento2.com/url-does-not-exist’,
‘http://magento2.com/url-does-not-exist’,
‘http://magento2.com/url-exist’);

I’ve tried curl, get_headers they all failed

output is wrong:

<a href=”http://magento2.com/url-exist” >Link-1</a>
<a href=”http://magento2.com/url-does-not-exist” >Link-2</a>
<a href=”http://magento2.com/url-does-not-exist” >Link-3</a>
<a href=”http://magento2.com/url-exist” >Link-4</a>

It should return only url 1 and 4 200 status code e.g:

<a href=”http://magento2.com/url-exist” >Link-1</a>
<a href=”http://magento2.com/url-exist” >Link-4</a>

However it’s returning all 200 but 2 and 3 should return 404

Anyone have any idea why ?

Thanks in advance!

Leave a Reply

Your email address will not be published. Required fields are marked *