I have a large static result and I'm trying the following changes:
This is my original static result example with 3 links and 2 differents domain names:
var json = {This is the static result with many links like this <a href=\"http://website.com/932427/post/something-else/\" target=\"_blank\"> and this is other link obviusly with another post id <a href=\"http://website.com/456543/post/another-something-else/\" target=\"_blank\">, this is another reference from another domain <a href=\"http://onother-website.com/23423/post/please-ingnore-this-domain/\" target=\"_blank\"> }
So, the originals url's I need to change are two, according with the above example:
http://website.com/932427/post/something-else/
http://website.com/456542/post/another-something-else/
And I want to change that links now with this format:
http://other_domain.com/id?=932427/
http://other_domain.com/id?=456543/
And the final result should look like this into the static result.
By the way I'm using node.js
Thanks in advance
Node.js has a built in module for parsing and constructing URLs. Your solution can be written as:
var url = require('url'); // Comes with Node.
// Get the path: '/932427/post/something-else/'
var path = url.parse('http://website.com/932427/post/something-else/').path;
var newUrl = url.format({
protocol: 'http',
host: 'other_domain.com',
query: { id: path.split('/')[1] }
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With