Edit url friendly user profile

2

Good

I have the friendly url routes in the htacess file I am viewing the users by url so by the profile file

link

But I wanted to now edit the profile of this user that is another file edit_profile.php but I wanted the url to look like this:

link

But I can not get it to work

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Rotas para o menu principal
RewriteRule ^(comer|dormir|comprar|servicos|lazer|o-que-visitar|login|recuperar-    password|registo|contactos|invite|erro|actualizar-password)$ index.php?controller=$1
# Rotas para os estabelecimentos
RewriteRule ^estabelecimentos/([a-zA-Z-0-9-_]+)$ index.php? controller=estabelecimentos&option=tipo&tipo=$1 [L]
RewriteRule ^([a-zA-Z-0-9-_]+)$ index.php?controller=ver_estabelecimento&option=local&local=$1
# Rotas dos Users
RewriteRule ^users/([a-zA-Z-0-9-_]+)$ index.php?controller=perfil&option=user_id&user_id=$1
#Erro 404
ErrorDocument 404 /erro
    
asked by anonymous 14.02.2015 / 17:57

1 answer

2

It would look like this:

# Rotas dos Users
RewriteRule ^users/([a-zA-Z-0-9-_]+)$ index.php?controller=perfil&option=user_id&user_id=$1
RewriteRule ^users/([a-zA-Z-0-9-_]+)/edit$ index.php?controller=editar_perfil&option=user_id&user_id=$1

RewriteRule always works in this same format.

RewriteRule [PADRÃO] [SUBSTITUIÇÃO]

That is, PADRÃO may contain only one value, or it may contain a regular expression that will be tested on the path of the current URL. If the result of this test is true, apache will redirect the request to what is set to SUBSTITUIÇÃO .

The users/([a-zA-Z-0-9-_]+)/edit snippet is a regular expression that will test if the URL path follows this pattern and then return the one that is between users/ and /edit to the substitution. The $1 used in the replacement URL is this value.

See more about regular expressions.

    
14.02.2015 / 18:32