Jump to content

[SOLVED] Rewrite URL's for External Sites


ciber

Recommended Posts

Well i've search the forum flap, but then again I might be searching for the wrong thing.

 

So far my research has found that a js file will be best for what i want to do ...

 

What do i want to do ... well i want my site to rewrite all external URL's so that I can redirect them to a page so that i can record all external URL's which users may click on.

 

What i mean by this is, if the html is at follows:

<a href="http://www.yoursite.com">

 

I want it to rewrite to the following:

<a href="http://www.mysite.com?url=http://www.yoursite.com">

 

Anyone know how I can do this in JS, or would it be better with htaccess...?!

 

Thanks

Link to comment
Share on other sites

no,

 

the link will be on a news site, so no - the problem why I cant do it manually is I have close to 1800 news articles I will need to update.

And also staff are not reliable enough to always add the link in.

 

So far I already have the page it will redirect to:

.../exit.php?url=http://www.mysite.com

 

I just need to get something that can rewrite the urls for external sites like the one above.

 

Does this make sense?

Link to comment
Share on other sites

Now, I'm just writing something to get things going:

 

Suppose you have the URL of the external site stored in a database and want to output links like this one ".../exit.php?url=http://www.mysite.com" or "http://www.mysite.com?url=http://www.yoursite.com" you could want something like this?

 

<?php

// Connect to database

// Query the database

while($news_item = mysql_fetch_array($get_news)) {

  echo 'Title: ' . $news_item['title'];
  echo 'Link: <a href=".../exit.php?url=' . $news_item['ext_site'] . '">' . $news_item['ext_site'] . '</a>';
  echo 'Link: <a href="http://www.mysite.com?url=' . $news_item['ext_site'] . '">' . $news_item['ext_site'] . '</a>';
}

?>


 

Of course the above code is very simple. I'm not trying to implicate you couldn't write that your self, just trying to get things going :)

Link to comment
Share on other sites

try

<?php
$text = '<a href="http://www.yoursite.com">
blah blah
<a href="http://www.yoursite.com/xxx">
<a href="http://www.mysite.com?url=http://www.yoursite.com/11">
<a href=".../exit.php?url=http://www.mysite.com">';
$text = preg_replace('#(?<=\<a href="http://)(?!www\.mysite\.com)([^"]*)#', 'www.mysite.com?url=http://\1', $text);
print_r($text);
?>

Link to comment
Share on other sites

thanks to everyone's help ... but im new at php so im bit slow.- sorry :-[

 

Now, I'm just writing something to get things going:

 

Suppose you have the URL of the external site stored in a database and want to output links like this one ".../exit.php?url=http://www.mysite.com" or "http://www.mysite.com?url=http://www.yoursite.com" you could want something like this?

 

<?php

// Connect to database

// Query the database

while($news_item = mysql_fetch_array($get_news)) {

 echo 'Title: ' . $news_item['title'];
 echo 'Link: <a href=".../exit.php?url=' . $news_item['ext_site'] . '">' . $news_item['ext_site'] . '</a>';
 echo 'Link: <a href="http://www.mysite.com?url=' . $news_item['ext_site'] . '">' . $news_item['ext_site'] . '</a>';
}

?>


 

Of course the above code is very simple. I'm not trying to implicate you couldn't write that your self, just trying to get things going :)

 

I am using a DB - but its a CMS - so i don't really want to edit anything

 

try

<?php
$text = '<a href="http://www.yoursite.com">
blah blah
<a href="http://www.yoursite.com/xxx">
<a href="http://www.mysite.com?url=http://www.yoursite.com/11">
<a href=".../exit.php?url=http://www.mysite.com">';
$text = preg_replace('#(?<=\<a href="http://)(?!www\.mysite\.com)([^"]*)#', 'www.mysite.com?url=http://\1', $text);
print_r($text);
?>

 

Sorry confused?!

 

-------------------------------------------------

 

Basically what I want is for my site to rewrite all my external urls so that they show in my exit page url ... i want to show the pages in a frame.

 

The current code is (EG):

<strong>A man dies in car</strong><br>
A man recently died in a tragic car accident along the Regional 62 road. The cause is still unknown.<br>
<a href=http://www.news.com/newsarticle555/>Click here to read the full article</a>

 

 

 

Now all I want is for some sort of htaccess/javascript/ something to rewrite the url so it directs to my exit page instead

The manipulated code is (EG):

<strong>A man dies in car</strong><br>
A man recently died in a tragic arc accident along the Regional 62 road. The cause is still unknown.<br>
<a href=http://www.mysite.com/exit.php?url=http://www.news.com/newsarticle555/>Click here to read the full article</a>

 

 

 

Like i said before i have already created my exit.php page, all i need now is something to change the url's

 

Thanks :D

Link to comment
Share on other sites

because ive then got to change +1800 news articles  :-\

I dont have any code, im trying to work out how to do it ...

 

im trying now to see if i can do this in htaccess ... but failing

Link to comment
Share on other sites

thought of something

 

if ahref not "www.mysite.com" then rewrite url to www.mysite.com?url=www.yoursite.com

 

does this make sense ?! its stupid but hope you understand now... :-[

 

 

 

-----------------

 

this is what my exit page looks like, now all i want is for the external urls to rewrite to the link http://www.mysite.com?url=...

http://www.gametab.com/news/2649075/

Link to comment
Share on other sites

here this is what i want so you can understand

 

Scroll down to ...

Script to anonymize all the links on your homepage or board

http://anonym.to/en.html

the problem with this is, the javascript is compressed i think so its useless

http://js.anonym.to/anonym/anonymize.js

except i dont want o anonymize my links, i just want them displayed through my exit.php page

 

 

and here is something as well:

http://custom.simplemachines.org/mods/index.php?mod=894

Link to comment
Share on other sites

You are thinking of this the wrong way....

 

Having 1800+ news articles isn't it problem because you have a single php script outputting your news articles.

 

Im 99.99% sure you have a script, which when called like below output the 10 latest news articles and have some pagination system to view older news articles:

 

www.mysite.com/viewnews.php

 

That script will somewhere (in it's code) query your database for news articles and output the fetched rows like you showed us earlier:

 

<?php

$get_news_articles = mysql_query("SELECT * FROM news ..... LIMIT 10");

while($news_article = mysql_fetch_array($get_news_articles) {

  // <strong>A man dies in car</strong><br>
  echo '<strong>' . $news_article['title'] . '</strong><br>';

  // A man recently died in a tragic car accident along the Regional 62 road. The cause is still unknown.<br>
  echo $news_article['preview'] . '<br>';

  // The link http://www.news.com/newsarticle555/
  echo '<a href="' . $news_article['link'] . '">Click here to read the full article</a>';
}
?>

 

All you need to do (as I understand your problem and what you are saying) is to locate your viewnews.php-script and change something like the above code from:

 

<?php
...

  // The link http://www.news.com/newsarticle555/
  echo '<a href="' . $news_article['link'] . '">Click here to read the full article</a>';
?>
...

 

to

 

 

<?php
...

  // The link http://www.news.com/newsarticle555/
  echo '<a href=http://www.mysite.com/exit.php?url="' . $news_article['link'] . '">Click here to read the full article</a>';
?>
...

Link to comment
Share on other sites

In my opinion the link and the cms you use doesn't change the way you should handle this.

 

May I suggest you tell the rest of the forum which cms you are using so someone who knows the cms can help you?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.