Hello Magento Friends,

Today I bring you the solution for How to Encode and Decode URL in Magento 2.

Encryption is used to share confidential information. The plain text is converted into an encoded text that no one can understand. The encrypted text is then converted back into plain text. This process is known as decryption.

If you want to pass product ID or user ID into the URL, you can use encode URL for security purposes. Let’s learn How to Encode and Decode URL in Magento 2.

Steps to Encode and Decode URL in Magento 2:

Step 1: You need to insert \Magento\Framework\Url\EncoderInterface class to encode the URL and \Magento\Framework\Url\DecoderInterface class to decode the URL. Both classes must be inserted in your construct. I added this code in the custom module’s block file.

You need to pass a URL as a parameter in getEncodeUrl() and getDecodeUrl() to return output.

Output :

Base URL :  baseurl/mymodule/index

Encode URL : pLzEyNy4wLjAuMS9tMjM0L2hlbGxvd29

Decode URL :  baseurl/mymodule/index


Hence, this way you can Encode and Decode URL in Magento 2. You can also Pass Parameter To URL In Magento 2. Share the article with your friends and stay in touch with us for upcoming Magento solutions.

Happy Coding!

Click to rate this post!
[Total: 0 Average: 0]