Hide folder path with . htaccess

Asked

Viewed 746 times

0

Olar. I’m working with a . htaccess file but I’m having a hard time getting what I need.

I have the mastery site.com.br/panel/view/painel_de_access.php and would like to convert this url into site.com.br/painel_de_access

What logic I could insert into mine. htaccess to get this done in this file and all other files that are inside the panel/view folder/?

1 answer

1

Create a file with the name in the root folder .htaccess and add this:

RewriteEngine On
RewriteRule ^([a-z0-9_]+)$ painel/view/$1.php [L]

If the files have uppercase and minute letters you can adjust it like this:

RewriteEngine On
RewriteRule ^([a-z0-9_]+)$ painel/view/$1.php [NC,L]
  • The ([a-z0-9_]+) search only files with name that has letters, numbers and underline

  • The ^ and the $ do check from start to finish to make the "match"

  • The $1 take whatever is inside the stop and add to get the request "true"

  • The NC makes the regex to be case-insenstive (at first there is no)

  • The L makes ignore the next rules (RewriteRule) avoiding conflicts

If it occurs error 500 may be two possibilities:

  • You have added something else within your . htaccess, which is conflicting
  • Or you haven’t enabled mod_rewrite in apache (which is a rare medium nowadays to occur)

Browser other questions tagged

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