Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6206901
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T05:32:03+00:00 2026-05-24T05:32:03+00:00

I’m really confused how many times should I encode a URL when it is

  • 0

I’m really confused how many times should I encode a URL when it is set as a value in a querystring ‘coz we know browser has their own encoding process. Here’s the scenario:

  • I want to redirect to another location which I want to pass the previous URL:
    Note: the current URL is http://localhost:8081/CostMonitoring/MainMenu.aspx?Option=AllCE

Method A (without encodeURIComponent()):

window.location = 'CostEstimateApproval.aspx?CEMID=40' + 
        '&ToStatus=1CE'+
        '&PrevURL=' + window.location;

I get this in the address bar

http://localhost:8081/CostMonitoring/CostEstimateApproval.aspx?CEMID=40&ToStatus=1CE&PrevURL=http://localhost:8081/CostMonitoring/MainMenu.aspx?Option=AllCE

without encodeURIComponent(), everything works fine and the value of Request.Querystring("PrevURL") in the receiving page is

http://localhost:8081/CostMonitoring/MainMenu.aspx?Option=AllCE 

which is correct.

Method B (with encodeURIComponent()):

window.location = 'CostEstimateApproval.aspx?CEMID=40' + 
        '&ToStatus=1CE'+
        '&PrevURL=' + encodeURIComponent(window.location);

with this method I get this in the address bar:

http://localhost:8081/CostMonitoring/CostEstimateApproval.aspx?CEMID=40&ToStatus=1CE&PrevURL=http%3A%2F%2Flocalhost%3A8081%2FCostMonitoring%2FMainMenu.aspx%3FOption%3DAllCE

and the value of Request.Querystring("PrevURL") in the receiving page is

http://localhost:8081/CostMonitoring/MainMenu.aspx?Option=AllCE 

which is also decoded correctly.

My questions:

  1. Should I encode the URL-as-value? Will it be redundant if I encode it then the browser encode it again?

  2. or should I let the browser encode it for me? If I let the browser, will the receiving page be confused from URL-as-a-value’s value to the real URL value? Please consider this example:

    http://www.domain.com/newpage.aspx?SameName=DifferentValue&PrevURL=http://www.domain.com/oldpage.aspx?SameName=DifferentValue&PrevURL=http://www.domain.com/anypage.aspx

as you can see, both URL (the real URL and the URL-as-a-value) when not encoded has the same data name which is SameName. How does the receiving side handle this? or the HTTP server?

Thanks in advance!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T05:32:03+00:00Added an answer on May 24, 2026 at 5:32 am

    You should use encodeURIComponent (once), since you’re encoding a url parameter.

    As you noted at the end of your question, failing to encode the url with encodeURIComponent would be problematic if your url included an &, for example.

    Note that your Method A only worked because your example prevUrl is somewhat simply formed, e.g. it doesn’t include a second url parameter.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to count how many characters a certain string has in PHP, but
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
Basically, what I'm trying to create is a page of div tags, each has
I've got a string that has curly quotes in it. I'd like to replace
Does anyone know how can I replace this 2 symbol below from the string
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have just tried to save a simple *.rtf file with some websites and
I would like to count the length of a string with PHP. The string

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.