-
Want to change a url
Hi I have a question.
I have a site that has an indexing searchengine on it (searchblox). There is a sub dir that is mapped to an actual domain name but it it a dir on another domain. Basically making http://www.myrealdomain/something/an...ir/index.shtml into http://www.mymappeddomain.com/index.shtml. Can someone point me in the correct direction to deal with something like this? The index will return the first full path url (by my understanding) anyway to make it go to the second url instead? Is preg_match or preg_replace (or a combo of both a valid solution). Thanks in advance for any help.
-
As a general practice it is best to avoid PCRE unless you need it because it is rather processor heavy. Perl, which is what PCRE is modeled after, is far less so.
If you just want to change the following:
http://www.myrealdomain/something/anotherdir/thisdir/index.shtml
to
http://www.myrealdomain/index.shtml
and something/anotherdir/thisdir/
is always the same maybe str_replace() would be a better choice in this situation?
I should add that I am not familiar with searchblox.
EDIT: you seem to be missing your top level domain. For example example.com where .com is the top level domain.
-
Hi James,
Thank you for the suggestions. The missing .com is a typo. Basically Searchblox is an indexing, search software. It pulls a
Code:
<title>
<url>
<description>
Tags from the indexed content. These tags are generated for each returned object from a given query. My question (forgive me if I am not explaining it correctly) can I turn the returned url (which would be
Code:
http://www.myrealdomain.com/something/anotherdir/thisdir/index.shtml
) into
Code:
http://www.mymappeddomain.com/index.shtml
and have the urls linkable?
Also the url string isnt always the same i.e.
Code:
http://www.myrealdomain.com/something/anotherdir/thisdir/index.shtml
is just one dir that needs indexed. There are several dir (all in the same dir) For example
Code:
http://www.myrealdomain.com/something/anotherdir/thisdir1/index.shtml
Code:
http://www.myrealdomain.com/something/anotherdir/thisdir2/index.shtml
Since the beginning of the url is always the same is str_replace() still a viable option?
Thanks
-
If I understand you correctly http://www.myrealdomain.com is always the same and index.shtml is almost always different, correct?
Here is the PCRE that would replace the middle directories that you said you don't want:
Code:
<?php
$test="http://www.myrealdomain.com/something/anotherdir/thisdir/index.shtml";
$test=preg_replace('/\.com\/.*\//','.com/',$test);
echo "$test";
?>
what would an example link look like as displayed to the user?
-
The url that the user would see would look like this:
Code:
http://www.mymappeddomain.com/dir1/somename.shtml
or
Code:
http://www.mymappeddomain.com/dir2/somename.shtml
etc.
I guess my question is more based on getting the data to look like it is coming from the
Code:
http://www.mymappeddomain.com
instead of
Code:
http://www.myrealdomain.com
Where it is actually located. I hope that makes sense.
-
This is not what you asked for earlier. To avoid confusion please give a real example of the preformatted data and what you want it to look like afterwards. It should be data you are working with instead of the hypothetical ones we've been using. Please show the link that you want users to see complete with the anchor tags like the following:
Code:
<a href="http://www.mysite.com/text.txt">http://www.mysite.com/text.txt</a>
preferably using the code tags so that it is formatted like above.
-
Code:
<?php
if (!isset($_GET['qry'])) {
echo '<ul class="listings-results search">';
echo "<li><h4>We’re sorry, search is currently undergoing maintenance.</h4></li></ul>"; //error check
}
$qry = urlencode($_GET['qry']);
$url = "http://mysearchserver.com/searchblox/servlet/SearchServlet?cname=inchicago&fe=utf-8&st=adv&q_phr=&q_low=&q_not=&oc=all&pagesize=100&q_all={$qry}";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$xml_string = curl_exec($ch);
curl_close($ch);
$xml = new SimpleXMLElement($xml_string);
if ($xml != ''){
echo '<ul class="listings-results search">';
}
foreach($xml->results->result as $the) {
echo '<li class="listing-results">'.'<a class="list-title" href="'.$the->url.'">'.'<h4>'.$the->title.'</h4>'.'</a>'.'<span class="desc">'.$the->description.'</span>'.'</li>'.'</ul>'; //output results
} ?>
When this is indexed the xml takes on the title, url, and description of each page. However, since the files reside on http://www.mytravelsite.com/states/c.../0/apage.shtml and the mapped drive for http://www.inchicago.com is the "thiscity" dir making this
The Real indexed URL
Code:
http://www.mytravelsite.com/states/cities/thiscity/0/apage.shtml
The one that needs to be returned to the client
Code:
http://www.inchicago.com/0/apage.shtml
Hopefully that will make my question clearer.
Thanks
-
Much clearer thanks. I am playing around with it to see what I can come up with. preg_match seems to be the way to go with this one.
-
I'm betting this pattern could be simplified, but here is what I came up with:
Code:
<?php
$test="http://www.mytravelsite.com/states/cities/thiscity/0/apage.shtml";
$test=preg_match('/\/(?!\/)[^\/]*?\/(?!(\/|.*?\/)).*/',$test, $extract);
echo "http://www.inchicago.com$extract[0]";
?>
I'm a bit out of practice with my PCRE knowledge.
-
Thank you for the information. I will let you know how it goes.