My RedirectURL already contains a query string:
https://mydomain.com/pages.php/?page=search-results
And when I place this in my settings for the search bar
redirectUrl: “pages.php/?page=search-results”
The net effect is a compound double “?” query string, in which Yext is also passing the same query parameter my CMS uses (page=), so I end up with a 404 error redirecting to:
https://mydomain.com/pages.php/?page=search-results?page=search&query=points
- How do I change the second “?” to “&”
- Can I supress the referring page value (page=search) as it will send user back to the search page
Hi there!
Welcome to the Community! This looks like a bug in our Answers product. I’ll raise it to our engineering team to take a look and get back to you with any updates. For more context, which CMS are you using?
Update from our engineering team - We don’t currently support this behavior, but have it planned in our roadmap. There exists a short-term workaround, but it’s “fragile”, not recommended, and also not guaranteed to work with future SDK versions. If that is something you are interested in, we can work with our engineering team to get you a solution, but again it is not recommended.
Is it possible for you to remove the query string from your redirect URL?
Hi Kristy,
Not really.
My redirected URL is sadasdxyz.com/?page=search_results
And when I run Yext from sadasdxyz.com/?page=search_bar, you’re transforming my querystring to: sadasdxyz.com/?page=search_results?page=search_bar&query=points
I didn’t want to have to play with .htaccess, but that may be the only viable solution, as I need to do two things:
(a) I need to rip out your own page reference ?page=search_bar when it exists; or
(b) regex transform ?query= to &query=
If your engineers have something that won’t make my brain bleed, I am all "y"ears
D.
Something similar to this:
RewriteCond %{QUERY_STRING} ^(.)?query=(.)$
RewriteRule ^(.*)$ /$1?%1&query=%2 [L,R=301]
RewriteCond %{QUERY_STRING} ^(.)?page=search-test&query=(.)$
RewriteRule ^(.*)$ /$1?%1&query=%2 [L,R=301]
The risk is the page name of my referring page (that you append as page=) may not be static, in which case, I would need to add one rule for every page name in the system where a search bar appears.
Hope that helps clarify my thinking (so far at least)
Hi again,
We will have support for query parameters in the search bar redirect URL in the next SDK version, which is planned for our Spring Release in a few months.
In the meantime, the workaround is to add the below onCreate config to your redirect SearchBar component. You can copy and paste it from this Gist: TECHOPS-3516, redirect searchbar redirectUrl with query params workaround · GitHub
Let us know if this works for you or if you have any questions!
I may need additional help
I modified my page header as follows (fake parameters), and perhaps there’s a parameter I was supposed to modify or remove? This is still forward passing to my page and getting messed up when your parameters are appended
Since it’s a bit difficult to help you debug without looking at your code, can you confirm this is how you set it up below? I added the onCreate function in the above Gist to the initialize library step of the search bar instructions. The initAnswers function for your search bar should look like the below:
<script>
function initAnswers() {
ANSWERS.init({
apiKey: "REPLACE_ME_API_KEY",
experienceKey: "REPLACE_ME_EXPERIENCE_KEY",
experienceVersion: "PRODUCTION",
locale: "en", // e.g. en
businessId: "REPLACE_ME_BUSINESS_ID",
templateBundle: TemplateBundle.default,
onReady: function() {
ANSWERS.addComponent("SearchBar", {
container: ".search_form",
name: "search-bar", //Must be unique for every search bar on the same page
redirectUrl: "REPLACE_ME_SEARCH_RESULT_URL",
placeholderText: "Search...",
onCreate() {
const originalQuerySubmit = this.onQuerySubmit;
this.onQuerySubmit = (inputEl, queryTrigger) => {
this.core.storage.setWithPersist('page', 'search-results');
originalQuerySubmit.call(this, inputEl, queryTrigger);
}
}
});
},
});
}
</script>
If this is what you did and the parameters are still appended, I’ll follow up with the engineer who was taking a look at this. It could be helpful for us to take a look at your search bar setup. Would you be able to share the page your search bar is on (a staging link is okay too)? You can send it to hitchhikers-support@yext.com to maintain your privacy.
Thanks!
Thanks Kristy,
Your code and my code matched.
After thinking thru your logic, I realized you needed me to redirect only to index.php and not index.php?search-results … made sense after I thought about what your code was doing.
We can close this, as this temp fix is working.
Doug
Hi Doug,
Glad to hear it worked! I’ll also follow up here when we have a new SDK version out with our Spring Release in case you need to make any updates.