0

I have the following relative URL (my website is www.web1.com).

<a href="/28518/verona-torino" target="partidos"> View! </a> 

I need another URL (not www.web1.com) inserted here, either from JavaScript, PHP, or .htaccess.

The code should be as follows:

<a href="http://www.web2.com/28518/verona-torino" target="partidos"> View! </a>

Editing the HTML manually is not an option.

8
  • 1
    Is the http://www.web2.com the same website that the link is on? Commented Feb 17, 2014 at 19:59
  • Well you could use .attr('href') to get the old url, add the old url after the absolute url you want and put it back in to the anchor. Commented Feb 17, 2014 at 20:00
  • This depends on what you are looking to do. Do you want the domain to be in the source code or just when you click. Commented Feb 17, 2014 at 20:01
  • The url I want to open is in web2.com, and the code is in web1.com Commented Feb 17, 2014 at 20:03
  • 1
    Are we dealing with plain html files? Or are you already using PHP to generate the website? Do you have other relative url that shouldn't be changed to the other domain? Or could you just use <base href="http://www.web2.com/" />? Commented Feb 17, 2014 at 20:04

2 Answers 2

1

Top of all PHP files

<?php
define('URL', 'http://www.web2.com/');
?>

In HTML you can now do this

<a href="<?php echo URL; ?>28518/verona-torino" target="partidos"> View! </a>
Sign up to request clarification or add additional context in comments.

1 Comment

SOLVED! Use <base href="web2.com/"; />. Thanks to all
0

If you use jquery library, this may help:

$.each('a', function() {
  var t = $(this).attr('href');
  $(this).attr('href', 'http://www.web2.com'+t);
});

Be aware that it's not SEO friendly way.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.