Querystring Question

I am using a querystring which calls an API and brings back data. But instead of this:

example.com/?id=bob

I would rather rewrite the url like this:

example.com/bob

Is this possible in the wix framework?

I am not using a database with this particular site…

THANKS

I’m not sure I understand.
Are you using ‘fetch’ to get data, or do you mean HTTP functions that exposes an API to your site?

Liran.

I use ?id=bob to fetch data from an API. That is all fine.

I want to rewrite the URL so it does not have to use ?id=bob (like in .htaccess - https://wiki.apache.org/httpd/RewriteQueryString).

It will easier for my users to use:
example.com/bob
instead of
example.com/?id=bob

No matter what, “bob” will be used to call my API.

These are customized user pages that they will use to promote their sales.

Does this make more sense?

example.com/ user/bob would work, however I do not want to store values for each user. That’s why I am calling our master system of record with the API.

Hi lperroots,
Breaking your question down, you wish to create a dynamic url path that routes to a custom page displaying information from a third-party API.

I would suggest using wix-router to achieve this.

To use a dynamic url path such as “yourdomain.com is available for purchase - Sedo.com” or “user.wixsite.com/site/users/dynamic_path” add a router to your site.
You can edit your routers.js backend code to get the request url path (see the examples in API reference links below), Create custom request to any API using wix-fetch .
You can then call wix-router ok() function to redirect the client to the user-display-page while passing wanted information to the display page as a data object.

Check out this article about creating a router:

And also these wix-code API references:
wix-router: wix-router - Velo API Reference - Wix.com
wix-fetch: wix-fetch - Velo API Reference - Wix.com

Let me know if that answered your question,
Omer.

Thanks. I think that will work!

Based on what I read, there’s no way to do this like this:

example.com/bob

It will have to be:

example.com/user/bob

Which is fine. I wonder if I can write some logic that can handle this or if a user enters example.com/bob it is pointed to example.com/user/bob

Hi,

You can create a new page named ‘bob’ and add a simple wixLocation.to function:


import wixLocation from 'wix-location';

  wixLocation.to("/user/bob");