Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
156
rated 0 times [  161] [ 5]  / answers: 1 / hits: 28639  / 13 Years ago, thu, october 13, 2011, 12:00:00

I want to redirect a user from varying urls to a specific one. I've tried various flavors of replacing and I cant seem to get the behavior I want. This code works except I'm providing the hostname. I want to use the existing hostname from windows.location.hostname and just provide a new pathname. Sometimes the urls vary in size and slashes ('/').



window.location = 'http://localhost:36065/NewPath';


How would I change these urls?



http://somesite.com/xxx/yyy/zzz to http://somesite.com/NewPath
http://somesite.com/xxx/yyy to http://somesite.com/NewPath
http://somesite.com/xxx to http://somesite.com/NewPath


I think you get the point. The path can vary in paths, I want to replace everything after .com basically with 'NewPath'



I'd like a clean regex solution if possible but I am quite the rookie in that dept. Thanks for any tips or tricks.


More From » regex

 Answers
22
location.pathname = '/newpath.html'

[#89626] Wednesday, October 12, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
emilianoc

Total Points: 568
Total Questions: 109
Total Answers: 99

Location: Oman
Member since Sat, Jan 7, 2023
1 Year ago
;