Sanjucool
Sanjucool

Reputation: 1

Removing unwanted characters from a URL

Recently I published a website and it's working fine. But when I try to open any linked page its URL looks like this:

http://www.englishseekhon.com/English%20Vocabulary%20with%20Hindi%20Meaning.html

As you can see, there are a number of %20 character sequences that I don't want to appear in the URL. How can this be fixed?

Upvotes: 0

Views: 459

Answers (2)

Meer
Meer

Reputation: 1026

Have a look at the code provided here: http://www.asiteaboutnothing.net/c_decode-url.html . The endcode() and decode() functions will do the trick.

<script> 
    function encode() { 
        var obj = document.getElementById('dencoder'); 
        var unencoded = obj.value; 
        obj.value = encodeURIComponent(unencoded); 
    }

    function decode() { 
        var obj = document.getElementById('dencoder'); 
        var encoded = obj.value; 
        obj.value = decodeURIComponent(encoded.replace(/\+/g, " ")); 
    } 
</script>

Upvotes: -1

zzzzBov
zzzzBov

Reputation: 179246

%20 is the correct percent encoded form of the space character. If you would like to use a "Friendly URL" format, you'll need to replace the spaces in the name of the resource with a different character.

Hyphens and underscores are generally recommended.

A "dasherized" form of the url would be:

http://www.englishseekhon.com/english-vocabulary-with-hindi-meaning.html

Upvotes: 3

Related Questions