0

I have a search in my page, like this:

<a href=/search/./1>First page</a>

So, mypage.com/search/./1 - I'm searching for .

What is happening is, the . is disappearing in the URL.

Place your mouse over the link in the snippet to see the problem.

What is causing this?

How to solve it if an user searches for .?

beerwin
  • 9,813
  • 6
  • 42
  • 57
RGS
  • 4,062
  • 4
  • 31
  • 67
  • 2
    because `./1` is almost similar to `/1`. or `1`. Please refer this [**SO Answer**](http://stackoverflow.com/a/2143422/4763084) – vivekkupadhyay Aug 10 '16 at 12:07

1 Answers1

1

This happens, because in file systems the . character represents the current folder, so

mypage.com/search/. == mypage.com/search/

The browsers know this, and they automatically strip the dot.

If I understand well, you would like to make your search SEO friendly.

You can do something like this:

Base64 encode the dot, and prepend it with some custom characters, which can tell your search code that this is base64 encoded.

If you have regular searches (no dot, but some meaningful expression), you leave it as it is.

For example:

Meaningful expression: some product

<a href="mysite.com/search/some%20product/1"`>First page</a>

some%20product is the urlencoded version of some product.

It is recommended to urlencode your search expression, to make it safer (so it works with any browser/server).

Dot:

<a href="mysite.com/search/B64E|Lg==/1">First page</a>

Where: Lg== is the base64 encoded .

In the case of base64 encoded stuff, you don't urlencode anything.

And in your search code, you can check for the existence of B64E| in the parameter, and if it exists, split your parameter on | and base64 decode the second element of the split result.

beerwin
  • 9,813
  • 6
  • 42
  • 57