4

We want to start uri encoding using encodeURI() our URLs during 301 redirect handling on our server. We have to handle special characters in other languages.

We want to make sure that we don't negatively impact our seo.

Do the bots treat the decoded url and the encoded url as the same/identical url?

example url:

https://example.com/product/piñata

https://example.com/product/pi%C3%B1ata


2
  • 1
    Can you give some example URLs? I think it may depend on what part of the URL is encoded. Jan 12 at 21:00
  • Just added an example. So no query parameters in this example. Only the main part of the URL is encoded or not
    – milesmeow
    Jan 12 at 23:02

1 Answer 1

1

Providing the URL is correctly URL-encoded (ie. %-encoded) then the URL-decoded (ie. "normal" or %-decoded) URL is identical to the URL-encoded URL. If a bot did treat it differently then that is a fault of the bot.

The purpose of URL encoding is so it can be transmitted reliably (in US-ASCII).

If you don't explicitly encode the URL then the browser is most probably implicitly encoding this for you before making the request (although it won't necessarily get this right or as you intended, depending on the URL).

For example, given the URL in the question /product/piñata. Even though this is not explicitly encoded, the browser implicitly encodes this as /product/pi%C3%B1ata before making the HTTP request. If you right-mouse and "Copy Link Address" (Chrome) then it copies the %-encoded URL.

We want to start uri encoding using encodeURI() our URLs during 301 redirect handling on our server.

(Presumably, you are using Node.js?)

Note that encodeURI() is not the only tool (and not the only tool you may need) to correctly URL-encode the URL. If you are using a query string and using reserved characters in the parameter values then you will also need encodeURIComponent().

2
  • The encodeURIComponent() would only be needed for the query string, otherwise it would encode all of the .:/? needed in the base part of the url right?
    – milesmeow
    Jan 12 at 23:50
  • 1
    @milesmeow Yes, encodeURIComponent() should only be used to encode URL parameter values in the query string.
    – MrWhite
    Jan 13 at 1:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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