I have two URL patten structure in $url
- news.oxo.com/site/data/html_dir/2013/05/25/2013052500007.html
- salute.com/arti/society/health/588947.html
and want to change those to
- m.oxo.com/article.html?contid=2013052500007
- m.salute.com/article.html?contid=2013052500007
I have tried
<?php $url_m = preg_replace("salute.com","m.salute.com",$url); ?>
<?php echo $url_m; ?>
And I guess I am totally lost -_-;;;;
Any help might be highly appreciated.
If you're responsible for both URLs and are using Apache you can handle the old addresses in the old Apache server with
.htaccess
:If you're not responsible and are only wanting to rewrite the URLs in PHP (if you're changing a link from a database for example), you would do this:
You can also replace the foreach with a string replacement as well if you're trying to replace links embedded in something like an article.
Thank you Absolute ZERO. I would like to multiply your ID with the infinite :)
I have tried your answer but it does not work. So I have made a little tweak on it. Before going on, I should clarify my situation a bit more to help for readers on this post.
I have a variable $urls in PHP. This is a link url for sending user to target page. In this variable, there are many patterns including those two:
news.oxo.com/site/data/html_dir/2013/05/25/2013052500007.html salute.com/arti/society/health/588947.html
With your answer and my tweak, I have managed to send users to mobile page.
I have one more question in regard of this question. Perhaps it would be right to post it by opening another question but since new question is closely related to the old one, I put this on here.
New question is what replacement and patterns should be used to replace
from
kr.hello.feedsportal.com/c/34762/f/640634/s/2c6bcfa2/l/0L0Shani0Bco0Bkr0Carti0Cpolitics0Cpolitics0Igeneral0C589130A0Bhtml/story01.htm
to
www.hello.co.kr/arti/society/society_general/589159.html
Thanks you!