What to do with a community URL type like Last.FM or Wikipedia?

I’m trying to understand how I can work with characters in URLs, because I create a site where the user can store content and go to the content page by specifying its name in URL.

so something like Wikipediaor Last.FMa website.

I see on the site, the user can write something like
http://it.wikipedia.org/wiki/Trentemøller, and the artist’s page can be reached.

after loading the page, if I copy the URL that I see as:
http://it.wikipedia.org/wiki/Trentemøllerbut if I paste it into a text editor, it will be pasted as
http://it.wikipedia.org/wiki/Trentem%C3%B8ller

therefore char is øinserted as%C3%B8

of course, for URLs like this (artist page Takeshi Kobayashi)

http://www.last.fm/music/小林武史
http://www.last.fm/music/%E5%B0%8F%E6%9E%97%E6%AD%A6%E5%8F%B2

If I am the first or second digit, the page works anyway, why?

I think I should do something with .htaccesand mod_rewrite, but I'm not sure if special characters are automatically converted to special characters URL?

and then, how can I make PHP make the right request with the content name?

if i have a table like

table_users
- username
- age
- height
- weight
- sex
- email
- country

I can mod_rewritewrite a type address with http://mysite.com/user/bobto get bb usernamefrom table_users, but what about http://mysite.com/user/小林武史?

here i am showing a simple example of what i think:

#.htaccess
RewriteEngine On
RewriteRule ^(user/)([a-zA-Z0-9_+-]+)([/]?)$ user.php?username=$2

<?php
// this is the page user.php
// this is the way I use to get the url value
print $_REQUEST["username"];
?>

this works, but it is limited to [a-zA-Z0-9 _ + -], how to be more compatible with all characters, such as others, without losing too much security?

Did anyone know how to avoid trouble?

+3
3

urlencode() 小林武史 %E5%B0%8F%E6%9E%97%E6%AD%A6%E5%8F%B2.

.htaccess mod_rewrite , - :

RewriteEngine On
RewriteRule ^(user/)(.+?)[/]?$ user.php?username=$2
+2
0

Source: https://habr.com/ru/post/1729814/


All Articles