I have created a rule for a page-redirect when a certain content type is viewed. if the search keyword is similar to any content of that particular content type then the search result page redirects as per the page redirects of the rule.

Eg: rule
event - Content is viewed
condition - Content is of the type "Animal"
Action - Redirect to a page

Assume that i already crated a content "African Elephant" of the type animal.

Issue:
If i search using either 'Elephant' or 'African' as search keyword. Instead of showing the search result page the rule action is triggered (In this scenario page redirection occurs)

Comments

russelljtdyer’s picture

I have the same problem. Are there no ideas to solve this? Is the problem with the Search module or the Rules module? What do y'all think?

Perhaps someone could suggest a condition that would exclude the Search module from my rule. I tried altering my rule to include a condition regarding the URL, thinking I could say that if it started with the path, /search that is should not apply. But that didn't work. Maybe I just don't know how to configure the rule, properly. I'd appreciate any suggestions on what I might try there.

Thanks in advance.

-Russell

russelljtdyer’s picture

I may have figured out the solution--at least the solution for my situation. After the search is performed, the Search module takes the user to the path /search/node/[search term], where the [search term] is the term entered by the user. If the search term is one for which there is a URL alias, it will redirect the user to that page, or at least as best it can. If there's not a URL alias for the term, the search page is displayed with the results. So the problem seems to be only with the search results page, not the searching.

Based on the above, I added a condition to my rule to solve the problem. I suggested this in my previous post, but this time I got it right. First I added a AND operator. Then I added the condition, Path has URL alias. For the Existing parameter path, I entered the value, /search/node. I also checked the Negate box for the condition. The result is that the search results page is not redirected and it works fine now.

UPDATE: I was wrong. That didn't work. I was just clobbering the rule so that it didn't work under any circumstance. But think I'm on the right path. I just need to figure out how to identify properly the path.

russelljtdyer’s picture

I think I've finally found a way around this problem. It requires the Context module (which I am already using), and the Context Rules module. The Context Rules module will integrate the Context module with the Rules module.

First I created a context and called it search-node--the name doesn't matter, though. I added to the Conditions section of the context, a condition based on Path. I entered a path of search/node/*. I gave no Reactions for the context. I don't want it to do anything other than determine the path matched. I then saved and went to the Rules configuration page (/admin/config/workflow/rules).

For my rule, I added an AND operator to the end of the conditions for the rule. Then I added a condition under the Context Rules section from the pull-down menu. I selected, Is a context set. That gave me another menu to select which context I want to set as a condition of the rule. I selected the one I just created, search-node. Then I checked the box for Negate and clicked Save.

I've tested pretty extensively this combination and it seems to hold up well. Hopefully, I'm finished with this problem and this thread and it is useful to others.

farse’s picture

#3 works a treat, thanks!

farse’s picture

Issue summary: View changes
Status: Active » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

Abhinesh Sharma’s picture

Great work @russelljtdyer

reinis.berzins’s picture

I managed to solve it without Context and Context Rules module. Just added a new condition "Check a truth value" to the basic Rules module and in "Truth Value" field wrote: <? return strpos($_SERVER['REQUEST_URI'], "search/node") == false; ?> to prevent executing redirection rule while on Search Results (search/node) page.