ciber Posted July 4, 2008 Share Posted July 4, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/113260-solved-rewrite-urls-for-external-sites/ Share on other sites More sharing options...
ciber Posted July 4, 2008 Author Share Posted July 4, 2008 Well i've search the forum flap... sorry typo - flat Quote Link to comment https://forums.phpfreaks.com/topic/113260-solved-rewrite-urls-for-external-sites/#findComment-581928 Share on other sites More sharing options...
DeanWhitehouse Posted July 4, 2008 Share Posted July 4, 2008 will the url in the link be userinputted? Quote Link to comment https://forums.phpfreaks.com/topic/113260-solved-rewrite-urls-for-external-sites/#findComment-581958 Share on other sites More sharing options...
ciber Posted July 5, 2008 Author Share Posted July 5, 2008 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? Quote Link to comment https://forums.phpfreaks.com/topic/113260-solved-rewrite-urls-for-external-sites/#findComment-582167 Share on other sites More sharing options...
Wuhtzu Posted July 5, 2008 Share Posted July 5, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/113260-solved-rewrite-urls-for-external-sites/#findComment-582177 Share on other sites More sharing options...
sasa Posted July 5, 2008 Share Posted July 5, 2008 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); ?> Quote Link to comment https://forums.phpfreaks.com/topic/113260-solved-rewrite-urls-for-external-sites/#findComment-582187 Share on other sites More sharing options...
ciber Posted July 5, 2008 Author Share Posted July 5, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/113260-solved-rewrite-urls-for-external-sites/#findComment-582204 Share on other sites More sharing options...
Wuhtzu Posted July 5, 2008 Share Posted July 5, 2008 Please show us some of the code with produces the output you just showed us. Why don't you just change what ever code output the link to output what you want? Quote Link to comment https://forums.phpfreaks.com/topic/113260-solved-rewrite-urls-for-external-sites/#findComment-582236 Share on other sites More sharing options...
ciber Posted July 5, 2008 Author Share Posted July 5, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/113260-solved-rewrite-urls-for-external-sites/#findComment-582244 Share on other sites More sharing options...
ciber Posted July 5, 2008 Author Share Posted July 5, 2008 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/ Quote Link to comment https://forums.phpfreaks.com/topic/113260-solved-rewrite-urls-for-external-sites/#findComment-582245 Share on other sites More sharing options...
ciber Posted July 5, 2008 Author Share Posted July 5, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/113260-solved-rewrite-urls-for-external-sites/#findComment-582255 Share on other sites More sharing options...
Wuhtzu Posted July 5, 2008 Share Posted July 5, 2008 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>'; ?> ... Quote Link to comment https://forums.phpfreaks.com/topic/113260-solved-rewrite-urls-for-external-sites/#findComment-582259 Share on other sites More sharing options...
ciber Posted July 5, 2008 Author Share Posted July 5, 2008 ive sent you PM with sites link ... Quote Link to comment https://forums.phpfreaks.com/topic/113260-solved-rewrite-urls-for-external-sites/#findComment-582266 Share on other sites More sharing options...
Wuhtzu Posted July 5, 2008 Share Posted July 5, 2008 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? Quote Link to comment https://forums.phpfreaks.com/topic/113260-solved-rewrite-urls-for-external-sites/#findComment-582288 Share on other sites More sharing options...
ciber Posted July 5, 2008 Author Share Posted July 5, 2008 urgh ... i give up ... thanks for your help anyways its something so minor its not worth it Quote Link to comment https://forums.phpfreaks.com/topic/113260-solved-rewrite-urls-for-external-sites/#findComment-582292 Share on other sites More sharing options...
ciber Posted July 5, 2008 Author Share Posted July 5, 2008 I GOT IT!!! Used a .js file!!! Thanks again!!!! Quote Link to comment https://forums.phpfreaks.com/topic/113260-solved-rewrite-urls-for-external-sites/#findComment-582296 Share on other sites More sharing options...
Wuhtzu Posted July 5, 2008 Share Posted July 5, 2008 So you are outputting all the markup using PHP and then changing the URL's with javascript afterwards? Quote Link to comment https://forums.phpfreaks.com/topic/113260-solved-rewrite-urls-for-external-sites/#findComment-582305 Share on other sites More sharing options...
ciber Posted July 5, 2008 Author Share Posted July 5, 2008 yes ... so cool when you get something working Quote Link to comment https://forums.phpfreaks.com/topic/113260-solved-rewrite-urls-for-external-sites/#findComment-582310 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.