How to add user name that is login in to my app to url ?

Hello, everyone!
Looks like webdev sub doesnt excepts questions … so i will try my luck here

I’d like to create a simple one-page web app. When a user logs in, they will have access to a basic page for editing. After they’re done, they can publish the page. Now, the issue I’m facing is as follows:

For example, if the user’s name is ‘adam1223,’ I would like it so that every time they try the URL http:// my-site dot com/adam123, it always redirects to their page, and not to something like http:// my-site dot com/id=adam123-sdsfsfs-sada123.

What is the name of this function in web development, and how can I achieve this (regardless of the web stack)?

Thank you very much!

You can do this via a server configuration file, depending on what type of server you have.
It’s likely to be Apache, Nginx or IIS.
So for example if it’s Apache, you would use an .htaccess file to configure this redirect.

im using go but i really what to understand the logic .
i don’t think i can set something static in the config file .
this should be totally dynamic .
user register , user added to the url

The config files can use Regex, so it’s not static as such.
What you are asking is very typical of what these files are used for.

For example in an Apache .htaccess file you may have:-

RewriteRule ^([0-9a-z]+)$ /?id=$1 [NC,L]

The first part is the URL you see. The regex means any numerical characters from 0 to 9 or any alpha characters from a to z. The + means any number of these. The () captures these.
The second part is where it is redirected, what the server sees. The $1 is substitiuted with the string captured in the first part.

So the user sees:-
https://example.com/adam123
But the server sees:-
https://example.com?id=adam123
It will work exactly the same for:-
https://example.com/sama74
or any other alpha/numeric string.

2 Likes

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.