Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+2 votes
294 views
in Q2A Core by
retagged by

I realized that when users enter text and search on my website the search result heading is displayed with a "+" in between the spaces.

For example if someone searches for "What is Facebook opengraph"

The result will come as: "What+is+facebook+opengraph". Searching for "Open graph" will return as "Open+graph".

If someone searches for a single word with space at the end, the space is returned as a "+". For example searching for "bookshop" returns "bookshop" in heading whereas searching for "bookshop " (notice the space after word) returns as "bookshop+".

How do I remove the "+" that replaces the spaces between words?

Q2A version: 1.8.8

2 Answers

+1 vote
by
selected by
 
Best answer

I've had this tab open for a week but I haven't had the change to reply to it. I haven't noticed this issue until now (in fact, I actually understood the question in one of the other comments). This is clearly a bug.

Check this PR: https://github.com/q2a/question2answer/pull/992/files

Apply those changes and let me know if the problem is gone. The explanation of the problem/fix is in the Comments tab.

by
reshown by
Hi @pupi1985,

I am not a techie but I tried your fix by logging in to my files and changing "rawurlencode" to "urlencode" in qa-include/qa-index.php (as you suggested here→ https://github.com/q2a/question2answer/pull/992/files ) and yes it works.

The "+" in search heading results is gone and now search results display correctly.

However, I think there's an issue (you can advise how to correct).

I just saw that the "url encoding thing" also affects how white spaces are output in usernames and according to your explanation here (1) and here (2)

1) https://www.question2answer.org/qa/109818/problem-with-issue-with-users-having-space-in-their-username?show=109838#c109838

2) https://www.question2answer.org/qa/106673/script-adding-sign-urls-whitespace-tags-usernames-please-help

The issue is solved by adding a B flang to the htaccess file.

I did that.

Now here are the issues being output:

Let's say a username has two names "John Doe"

When I click on the username, it still outputs the URL as:
https://example.com/user/John%20Doe

And not https://example.com/user/John+Doe as intended.

When I input the URL directly in the browser URL and replace "%20" with "+" between John and Doe (e.g https://example.com/user/john+doe) it still goes to the user's profile (as correctly intended) but the browser header displays as

"Search results for John Doe on Example"

Which is not intended because I have not searched anything and this is a user profile. I believe it should display as "John Doe on Example"

Also I noticed that if I search for two terms with a '+' in between as "x+y" the URL structure becomes:

https://example.com/searc/q=x%2By

Also if a username has three parts e.g "Jane John Doe", you can input the URL directly as

https://example.com/user/jane+john+doe
https://example.com/user/jane+john%20doe
https://example.com/user/jane%20john+doe

And they'll all go to the user's page on the website but the browser displays:

"search results for username on website"

Is this a bug or intended?
How do I correct that?

Thanks in advance, sorry for the long explanation. (PS, I don't know programming so I had to explain )
by
A few clarifications:

1. TL;DR https://example.com/user/John%20Doe should be used instead of https://example.com/user/John+Doe

Even though the plus sign is legal there, it shouldn't be legal in the query string (after the question mark). This can be better explained with an example:

 * This URL: http://example.com/search?q=a+b
 * Has this query string: q=a+b
 * But Q2A changes it to: qa-rewrite=search&q=a+b

So "search" eventually becomes part of the query string. So even though a plus sign is legal before the question mark, it will be moved after the question mark, and according to standards, plus signs shouldn't show up in that part of the URL.

So https://example.com/user/John+Doe would mean moving a plus sign to the query string, so it should be encoded like https://example.com/user/John%2BDoe (note '%2B' is '+'), which is not the intention. The logical step is to make sure the part before the question mark has a space, (note '%20' is ' ')

I want to clarify that this "weird" movement of texts between the right and left part of the question mark is non-standard. It is only intended to support different URL schemas. That complexity is the price to pay for that feature.

2. The "Search results for John Doe on Example" issue is a mystery. I think you have configured your browser to use that page as a search engine (of the brower) so that is why it is triggering the search page. If you send me a video with this I can confirm it. You can also try this in a different browser to confirm my theory.

3. Searching for "x+y" should result in an URL that looks like "x%2By" and the title of the search should show "Search results for x+y". I think this all makes sense

4. The "search results for username on website" issue I guess it is the same as #2. I would need a video as well.
by
Thanks again,

About the "Search results for user on website" it is displayed as the tab heading on browsers.

I have tried with different browsers (opera, chrome, X browser) and it appears that way on all of them.

When you click on a username on the website, it opens the user's profile page but the tab heading reads as search results.

For example, if I was to click on your profile, it the browsers would display as:

 "Search results for pupi1985 on Question2Answer"

While I could send you a video as requested, I think it would be better if I show you the live thing. So I have sent you the url to my live website so that you check any user profile and see for yourself.  

I've sent you the website URL via inbox, hope that's okay.
by
+1
1. Are you 100%, actually, 200% sure this is happening AFTER my suggested changes and that it DID NOT happen BEFORE?
2. Does changing the theme solve the issue?
3. Does disabling all plugins solve the issue?
4. Have you modified the translation files? Either way, re-download the qa-include/lang/*.php files and replace the ones you have
by
Okay did what you said and found the culprit:

1. No
2. No
3. Yes (the culprit)
4. Yes (not the issue)

So I disabled and (re)enabled plugins one-by-one  as you said...
...and it happens that "q2a Ultimate SEO" plugin was the issue.

I have made required changes to it and now the issue is gone.

NOTE: I think it is coincidence that I noticed this immediately after making the changes earlier that's why I tied the issue to those changes.

Thanks man, now problem solved.

1) Search title is displaying correctly as "Search results for query" without the "+" in between.
2) URL to user pages are structured well.
3) The "Search results for username on website" is now displaying well as just "username on website" as intended.

________
**I've also selected this answer so that it helps anyone with same issue in future.
by
Oh, I see. The Ultimate SEO allows page titles to be changed. If what you are seeing is a bug, and you happen to be using my fork of the project ( which is here: https://github.com/pupi1985/q2a-ultimate-seo ), just let me know and I'll take a look at it
by
Don't know if it's a bug but I know how it happens.

On the q2a Ultimate SEO plugin customisation settings there's the section for "Page Title Customizations" (actually the first customization option)

The last entry on that section is for "User's profile page" and there are three variables to use:
The section reads like this:

•Title for "User's Profile Page":
• available title variables for this page: %site-title%, %user-x%, %current-user%

If you use the option %user-x% it displays as "Search results for user"

I've set my option for the variables as "%user-x% on %site-title%" so the page title is displayed as "Search results for username on website"

I don't know if this is the intention of the plugin or not?

Note: if you use the variable %current-user% the page title displays correctly without the "Search results for...." part.


2) And yes it works that way for both Tohwids (original) version and your (forked) version of the plugin.
by
I see. I have just fixed the issue in my fork. Feel free to update it from here: https://github.com/pupi1985/q2a-ultimate-seo/releases/latest
0 votes
by
I think it needs the "+" sign to represent the URL for the search results. It doesn't work with a space.
by
It doesn't appear in the URL, instead it appears on the heading which starts with "Search results for...."

The URL structure usually replaces spaces between terms with hyphens (-) or for my website it uses %2B.

But the results have a "+" for spaces instead.
by
If you search on this website for a query like "What is q2a" it will display results and the heading at the top will read:

Search results for What is q2a

The URL string will be https://.../search?q=what-is-q2a
__ _ __ _ __ _ __ _

But for my website, the heading reads:

Search results for What+is+q2a (notice the difference?)

Whereas the URL is https://.../search?q=what%2Bis%2Bq2a

__ _ ___ _ __ _ ___

I want to remove the + in the returned heading.
...