0

How can I redirect to specific url that appear in the url parameter?

example:

http://www.mywebsite.com/Code_id.tv/stream.php

I want to get code_id and I will redirect to specific URL.

The result URL will eventually look like this:

http://www.mynewwebsite.com/tv.php?id=Code_id

Thanks

pakel
  • 3
  • 1
  • 2

1 Answers1

0

To split the path to get the code_id:

var url2Process = window.location.pathname;
var patharray = url2Process.split( '/' );

// remove '.tv' or '.movie' or '.whatever' from the end
var code_id_array = patharray[1].split('.');
var code_id = code_id_array[0];

// redirect
window.location = 'http://domain.com/rb/play.php?id=tt' + code_id;
Patrick Murphy
  • 2,311
  • 14
  • 17
  • How to redirect with specific ip address country ? example : I want to redirect if US country visitor only – pakel Jul 01 '15 at 18:43
  • Make an ajax call client side to this http://api.hostip.info/get_json.php and it returns what country the user is in – Patrick Murphy Jul 01 '15 at 18:46
  • my knowledge about api and javascript is not enough :( I hope you can give me sample code :) – pakel Jul 01 '15 at 18:56
  • Look here http://stackoverflow.com/questions/17680413/get-visitors-language-country-code-with-javascript-client-side then just use result.countrycode to test if it is equal to `US` `$.getJSON('http://freegeoip.net/json', function(result) { alert(result.country_code); });` – Patrick Murphy Jul 01 '15 at 19:46