Edit url user profile friendly

Asked

Viewed 74 times

2

Good

I have the paths of the friendly urls in the htacess file I am viewing the users by the url so by the profile file

http://exmeplo.pt/users/carlos

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

http://exmeplo.pt/users/carlos/edit

But I can’t 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
  • Always put your .htaccess in question. Without it it may be that someone proposes an answer that is not compatible with their current rules.

  • You’re right forgetting my part I already put

1 answer

2


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 to say, PADRÃO may contain only one value or may contain one regular expression which will be tested on the current URL path. If the result of this test is true, apache will redirect the request to what is set in SUBSTITUIÇÃO.

The excerpt users/([a-zA-Z-0-9-_]+)/edit is a regular expression that will test if the path of the URL follows this pattern and then returns what is between users/ and /edit for the replacement. The $1 used in the replacement URL is this value.

See more about regular expressions.

  • And that worked well still I am new in this of friendly urls I always used by string but not and the most indicated I will have to study better about it

Browser other questions tagged

You are not signed in. Login or sign up in order to post.