Page 1 of 2 12 LastLast
Results 1 to 10 of 18

Thread: Want to change a url

  1. #1
    Join Date
    Nov 2009
    Posts
    107
    Thanks
    7
    Thanked 2 Times in 2 Posts

    Default 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.

  2. #2
    Join Date
    Jan 2007
    Location
    Davenport, Iowa
    Posts
    1,730
    Thanks
    82
    Thanked 90 Times in 88 Posts

    Default

    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.
    Last edited by james438; 02-16-2013 at 05:59 AM.
    To choose the lesser of two evils is still to choose evil. My personal site

  3. #3
    Join Date
    Nov 2009
    Posts
    107
    Thanks
    7
    Thanked 2 Times in 2 Posts

    Default

    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

  4. #4
    Join Date
    Jan 2007
    Location
    Davenport, Iowa
    Posts
    1,730
    Thanks
    82
    Thanked 90 Times in 88 Posts

    Default

    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?
    To choose the lesser of two evils is still to choose evil. My personal site

  5. #5
    Join Date
    Nov 2009
    Posts
    107
    Thanks
    7
    Thanked 2 Times in 2 Posts

    Default

    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.

  6. #6
    Join Date
    Jan 2007
    Location
    Davenport, Iowa
    Posts
    1,730
    Thanks
    82
    Thanked 90 Times in 88 Posts

    Default

    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.
    Last edited by james438; 02-16-2013 at 05:18 PM.
    To choose the lesser of two evils is still to choose evil. My personal site

  7. #7
    Join Date
    Nov 2009
    Posts
    107
    Thanks
    7
    Thanked 2 Times in 2 Posts

    Default

    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

  8. #8
    Join Date
    Jan 2007
    Location
    Davenport, Iowa
    Posts
    1,730
    Thanks
    82
    Thanked 90 Times in 88 Posts

    Default

    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.
    Last edited by james438; 02-16-2013 at 08:04 PM.
    To choose the lesser of two evils is still to choose evil. My personal site

  9. #9
    Join Date
    Jan 2007
    Location
    Davenport, Iowa
    Posts
    1,730
    Thanks
    82
    Thanked 90 Times in 88 Posts

    Default

    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.
    To choose the lesser of two evils is still to choose evil. My personal site

  10. #10
    Join Date
    Nov 2009
    Posts
    107
    Thanks
    7
    Thanked 2 Times in 2 Posts

    Default

    Thank you for the information. I will let you know how it goes.

Similar Threads

  1. ajaxcars.zip how to change url on change of div
    By shahgm in forum Dynamic Drive scripts help
    Replies: 0
    Last Post: 03-21-2011, 01:51 AM
  2. on change(dropdown) change 2 div
    By emanuelle in forum JavaScript
    Replies: 1
    Last Post: 06-20-2010, 10:11 AM
  3. Html change on click, change to another html when clicked again
    By ShiWenBin in forum Looking for such a script or service
    Replies: 1
    Last Post: 11-04-2007, 01:11 AM
  4. name change?
    By boogyman in forum The lounge
    Replies: 12
    Last Post: 05-20-2007, 11:24 PM
  5. Change Var
    By Tabo in forum JavaScript
    Replies: 4
    Last Post: 04-24-2007, 09:04 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •