May 13, 2011

How to use jquery rewrite redirect url

Question by user610983

I created a drop down list(with javascript onchange features), I would like to rewrite the redirect url from this: http://localhost/en/abc/kk.php?CT=1 to http://localhost/abc/kk.php?lang=en&CT=1 by using jquery.

Possible to do it?

Answer by Starx

You cannot rewrite the redirect url through clientside script such as javascript itself. You need .htaccess file to do so.

However, if the urls http://localhost/en/abc/kk.php?CT=1 is already present in your markup like in anchor tags

<a href="http://localhost/en/abc/kk.php?CT=1">Some Link Text</a>

Then you can use jQuery to change the value

$(document).ready(function() {
    $("a").attr("href","http://localhost/abc/kk.php?lang=en&CT=1");
    //It is better to replace the values using pattern mathcing
});

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+

...

Please fill the form - I will response as fast as I can!