Publisher does not support the Fluid field type. Please do not contact asking when support will be available.

If you purchased an add-on from expressionengine.com, be sure to visit boldminded.com/claim to add the license to your account here on boldminded.com.

Ticket: Search does not redirects to result page if URL prefix enabled

Status Resolved
Add-on / Version Publisher 1.6.6
Severity
EE Version 2.10.1

Marijan Boljar

Oct 27, 2015

Description:

If URL prefix is enabled then search result redirects to home page.
Have tried with Channel URL and Search Results URL settings set to /glossary/ and /glossary/search-results/, have tried with {site_url}glossary (for Channel URL) and {site_url}glossary/search-results (for Search Results URL, and have tried to leave this empty also.

Whatever option I try I always get redirected to home page instead search results.
If I turn off URL prefix in Publisher settings then all works without problems and search results are displayed.

Also Site URL in config.php is set to full domain name.

Can you please help and check this issue.

Detailed steps to reproduce the issue:
1. Enable URL prefix
2. Create Simple Search form
3. Create Results page
4. Try to search

As I mentioned, if URL prefix is disabled then all works ok.

#1

BoldMinded (Brian)

Are you using the native search form or something like Low Search?

#2

Marijan Boljar

Native search form

#3

BoldMinded (Brian)

Can you share the search form tag as it is in your template, and the parsed version of it from your browser?

#4

Marijan Boljar

Hello Rein,

sorry for delay, here us code.

TEMPLATE CODE

<div class="filter-bar-search-input-wrapper">
 {exp:search:simple_form 
 name="search_form" 
 channel="glossary" 
 search_in="everywhere" 
 result_page="glossary/search-results" 
 no_result_page="glossary/no-results"  
 }
 <input type="text" name="keywords" id="keywords" class="filter-bar-search-input">
 {/exp:search:simple_form}
</div>

BROWSER CODE

<div class="filter-bar-search-input-wrapper">
 <form name="search_form" method="post" action="http://infobip.dev/en/">
        <div class="hiddenFields">
            <input type="hidden" name="ACT" value="6">
            <input type="hidden" name="RES" value="">
            <input type="hidden" name="meta" value="pD2/6Cz8PVdLSgUhIkIe/VTuOo1OXf/J9odQzWU1g6NTa+AEMe+Ma4VysaiuvGjGU68KhI/MmVDJSsfdFjzR1FFt+yEydvnWSjIiYCrwX5Jg9KG8V5sDJqKLZfP216UnYZLwXlplgl0VtbaMT4PWzMQylvUsYFFW+rYXkNGosL+r+/AVTOcj4beIsvJdgDiikrjVwMLxC/uUEO1PPxNKV1GMSiIb3CTSUYOmcxSouCizyN26/+BOhUDJdBBx9126+YpQap7uWmtthf8XLjVHzZzhi6R+qjLJalyblMtMhRzQLNRKQg2TERxh20aryD54+AVom7LYfPKOZX9/zLUdr6fh85aEhMKyxdk6gVE8xGpyr0kpjONg9WvHhnRrIyjfkjdUqryps7pUOIvR2JsGsH092z/i//tBZpuy6QzdXcw=">
            <input type="hidden" name="site_id" value="1">
            <input type="hidden" name="csrf_token" value="9c721493a201b0e0b07454cf6d68202736e606bf">
        </div>
 <input type="text" name="keywords" id="keywords" class="filter-bar-search-input"></form>
</div>

Let me know if anything else is needed. Thanks, Marijan

#5

Marijan Boljar

Sorry , should be “Hello Brian” No morning coffee still 😊

#6

BoldMinded (Brian)

Can you do me a favor and go to the Publisher_search.php class around line 93 and you’ll see this function.

public function get_meta_vars()
    {
        $this->_get_meta_vars();
        return $this->_meta;
    }

change it to

public function get_meta_vars()
    {
        $this->_get_meta_vars();
var_dump($this->_meta);
        return $this->_meta;
    }

Then share the output when you reload the search page.

#7

Marijan Boljar

This is browser code after adding var_dump

<form name="search_form" method="post" action="http://infobip.dev/en/">
    <div class="hiddenFields">
        <input type="hidden" name="ACT" value="6">
        <input type="hidden" name="RES" value="">
        <input type="hidden" name="meta" value="pD2/6Cz8PVdLSgUhIkIe/VTuOo1OXf/J9odQzWU1g6NTa+AEMe+Ma4VysaiuvGjGU68KhI/MmVDJSsfdFjzR1FFt+yEydvnWSjIiYCrwX5Jg9KG8V5sDJqKLZfP216UnYZLwXlplgl0VtbaMT4PWzMQylvUsYFFW+rYXkNGosL+r+/AVTOcj4beIsvJdgDiikrjVwMLxC/uUEO1PPxNKV1GMSiIb3CTSUYOmcxSouCizyN26/+BOhUDJdBBx9126+YpQap7uWmtthf8XLjVHzZzhi6R+qjLJalyblMtMhRzQLNRKQg2TERxh20aryD54+AVom7LYfPKOZX9/zLUdr6fh85aEhMKyxdk6gVE8xGpyr0kpjONg9WvHhnRrIyjfkjdUqryps7pUOIvR2JsGsH092z/i//tBZpuy6QzdXcw=">
        <input type="hidden" name="site_id" value="1">
        <input type="hidden" name="csrf_token" value="5ccf469347bb0018593f8ed04afba5bd93824694">
    </div>
    <input type="text" name="keywords" id="keywords" class="filter-bar-search-input">
</form>

I also get PHP warning when added this line

Severity: Warning
Message: Cannot modify header information - headers already sent by (output started at /Applications/MAMP/htdocs/infobip.com/_site/app/add-ons/publisher/libraries/Publisher/Publisher_search.php:96)
Filename: core/Common.php
Line Number: 479

If I comment var_dump Warning goes away.

#8

BoldMinded (Brian)

Change the var_dump to ee()->publisher_log->to-file($this->_meta);

It should save it to cache/publisher/log.txt

#9

Marijan Boljar

When using this code I get

A PHP Error was encountered
Severity: Notice
Message: Undefined property: Publisher_log::$to
Filename: Publisher/Publisher_search.php
Line Number: 96
A PHP Error was encountered
Severity: Warning
Message: file() expects parameter 1 to be a valid path, array given
Filename: Publisher/Publisher_search.php
Line Number: 96
A PHP Error was encountered
Severity: Warning
Message: Cannot modify header information - headers already sent by (output started at /home/ibstaging/system/codeigniter/system/core/Exceptions.php:170)
Filename: core/Common.php
Line Number: 475
#10

BoldMinded (Brian)

oh, its ee()->publisher_log->to_file($this->_meta);

to_file, not to-file. Sorry about that.

#11

Marijan Boljar

No prob Brian.

Here is result from log.txt

Array
(
    [status] => 
    [channel] => glossary
    [category] => 
    [search_in] => everywhere
    [where] => all
    [show_expired] => 
    [show_future_entries] => 
    [result_page] => glossary/search-results
    [no_results_page] => glossary/no-results
)
#12

BoldMinded (Brian)

Ok, lets try something else. Find the src/Service/Parser.php file and add these two lines, then just load the page that has the search form tag on it.

https://www.dropbox.com/s/jv2fx0w3ip5wxrc/Screenshot 2015-10-29 09.03.00.png?dl=0

#13

Marijan Boljar

Ok , done, now we have log.txt looking like this.

Array
(
    [status] => 
    [channel] => glossary
    [category] => 
    [search_in] => everywhere
    [where] => all
    [show_expired] => 
    [show_future_entries] => 
    [result_page] => glossary/search-results
    [no_results_page] => glossary/no-results
)

Array
(
    [status] => 
    [channel] => glossary
    [category] => 
    [search_in] => everywhere
    [where] => all
    [show_expired] => 
    [show_future_entries] => 
    [result_page] => en/glossary/search-results/
    [no_results_page] => glossary/no-results
)
#14

BoldMinded (Brian)

Ok, in that 2nd conditional in the screenshot, fix the variable name:

$meta[‘no_results_page’] = ee()->publisher_helper_url->swap_url($meta[‘no_results_page’], FALSE);

It currently said no_result_page, should be plural.

After that, it should be redirecting to those pages properly. Try going directly to en/glossary/search-results/ in your browser and see what happens. Try it with and without the trailing slash.

#15

Marijan Boljar

Here are details Brian

I needed to change “meta_no_result” also where conditional is set to get prefix “en” in front of no result URL. I think this is what you wanted, if I am correct.

So this was changed (~ 426)

if (isset($meta['no_result_page']))

with

if (isset($meta['no_results_page']))

and this (~ 428)

$meta['no_result_page'] = ee()->publisher_helper_url->swap_url($meta['no_results_page'], FALSE);

with

$meta['no_results_page'] = ee()->publisher_helper_url->swap_url($meta['no_results_page'], FALSE);

So after those two changes log.txt contains

Array
(
    [status] => 
    [channel] => glossary
    [category] => 
    [search_in] => everywhere
    [where] => all
    [show_expired] => 
    [show_future_entries] => 
    [result_page] => glossary/search-results
    [no_results_page] => glossary/no-results
)

Array
(
    [status] => 
    [channel] => glossary
    [category] => 
    [search_in] => everywhere
    [where] => all
    [show_expired] => 
    [show_future_entries] => 
    [result_page] => en/glossary/search-results/
    [no_results_page] => en/glossary/no-results/
)

Without changing

if (isset($meta['no_result_page']))

to

if (isset($meta['no_results_page']))

, there was no prefix added.

But still if there is URL prefix present in URL, search result for term that exists or does not exists returns to homepage, it does not redirect to result or no result page. If search is done from homepage where there is no URL prefix, or from other pages when URL prefixes are turned off then it all works ok. As soon as there is URL prefix present, it redirects to homepage.

Here are pictures

https://dl.dropboxusercontent.com/u/24921882/Direct_URL_enter.png https://dl.dropboxusercontent.com/u/24921882/Search_URL_Prefix_OFF_no_results.png https://dl.dropboxusercontent.com/u/24921882/Search_URL_Prefix_OFF_with_results.png https://dl.dropboxusercontent.com/u/24921882/Search_with_URL_prefix_on_resturns_to_homepage.png

Do you have any idea ?

#16

BoldMinded (Brian)

Check my previous comment about going to the pages directly, without performing a search. Just type them into the browser with and without the trailing slash. What happens then?

#17

BoldMinded (Brian)

I just tested this locally and the results and no-results pages work fine for me.

https://www.dropbox.com/s/jsyc0mwqca9bwip/Screenshot 2015-11-01 06.59.25.png?dl=0

My templates

{exp:search:simple_form channel="pages"
    search_in="everywhere" where="all"
    result_page="search/native-results"
    no_results_page="search/no-native-results"}

        <label for="keywords">Search:</label>

        <input type="text" name="keywords" id="keywords" value="" size="18" maxlength="100">


        <input type="submit" value="submit" class="submit">

{/exp:search:simple_form}
{exp:search:search_results switch="resultRowOne|resultRowTwo"}

    <tr class="{switch}">
        <td width="30%" valign="top"><b><a href="http://{auto_path}">{title}</a></b></td>
        <td width="30%" valign="top">{excerpt}</td>
        <td width="10%" valign="top"><a href="http://{member_path=member/index}">{author}</a></td>
        <td width="10%" valign="top">{entry_date format="%m/%d/%y"}</td>
        <td width="10%" valign="top">{comment_total}</td>
        <td width="10%" valign="top">{recent_comment_date format="%m/%d/%y"}</td>
    </tr>

    {if count == total_results}
        </table>
    {/if}

    {paginate}
        Page {current_page} of {total_pages} pages {pagination_links}
    {/paginate}

{/exp:search:search_results}
#18

BoldMinded (Brian)

Also, per the docs, it is no_result_page, not no_results_page. https://ellislab.com/expressionengine/user-guide/add-ons/search/simple.html#parameters

#19

Marijan Boljar

Hello Brian,

sorry for delay but I was doing lot’s of implementation and also wanted to do a really throughout testing of this issue.

I think I have found a problem, would you please be so kind to test and check ?

I had a URL rewrite in Apache to remove ending trailing slash. When I removed this rewrite rule search started to work with or without prefixes.

Here is htaccess code that was removed and all started to work.

# Remove trailing slash
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^(.*)/$
RewriteRule ^(.*)/$ /$1 [R=301,L]

Do you have any alternative to this code or maybe a suggestion ? Thanks for all your help.

#20

BoldMinded (Brian)

I can’t help with the htaccess file, but I can remove the trailing slash from the URLs that Publisher is creating, which it shouldn’t be adding by default (which is why I asked about accessing the page directly earlier with and without the slash).

#21

BoldMinded (Brian)

Comment has been marked private.

#22

Marijan Boljar

I have provided screenshot with Direct URL enter to search results 4 days ago as screenshot. Here it is again just in case.

For both cases (with or without trailing slash) result is the same, if I go direct to the URL with search results it gives EE message “Your search did not return any results.” https://dl.dropboxusercontent.com/u/24921882/Direct_URL_enter.png

If there is search entered in input field that has no results, this displays “no_result_page” that was defined.

#23

BoldMinded (Brian)

Are you positive that the text you are searching for exists in the language you’re on? The search feature has been implemented for awhile in Publisher now with no similar issues reported, and I can’t replicate the issue locally (searching works fine for me), and when these two things happen, it usually indicates an environment specific issue, either with the server, htaccess, incorrect template code, bad data etc.

Have you tried replicating this in a clean EE environment?

#24

Marijan Boljar

We did not understand each other good. Searching text works great now, no issues.

With or without prefixes all works great.

I just provided you with image of what happens when you enter url of search results directly. So the screenshot above is what you asked, to quote “Try going directly to en/glossary/search-results/ in your browser and see what happens. Try it with and without the trailing slash.”

So I tried to access page and just provided you with results.

It works like this, there are 3 cases (direct URL enter without search, search for keyword that exists, and search for keyword that does not exists)

  1. If URL is entered directly for example http://infobip.staging/en/glossary/search-results or http://infobip.staging/en/glossary/search-results/ then EE system message is shown
  2. If results are found, search result page with results is displayed
  3. If there is no results, no result page is displayed

All is good 😊 All works

Login to reply