Make sure that the URL you are trying to share is correctly generated in Magento. Go to the backend of Magento and check if the product or category URL is working fine directly in your browser. If the link works fine on the website but not when shared, then it's likely an issue with social sharing and metadata, not the URL structure.