Hide folder path with .htaccess

0

Olar. I'm working with a .htaccess file but I'm having a hard time performing what I need.

I have the domain site.com.br/painel/view/painel_de_acesso.php and would like to convert this url to site.com.br/painel_de_acesso

>

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

    
asked by anonymous 04.11.2017 / 18:43

1 answer

1

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

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

If the files are case-sensitive, you can do the following:

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

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

  • The $1 takes what you have inside the parantes and adds to get the "true" request

  • The NC causes regex to be case-insensitive (in the first case it does not)

  • The L ignores the next rules ( RewriteRule ) avoiding conflicts

If error 500 occurs, there are two possibilities:

  • You added something else inside your .htaccess, which is conflicting
  • Or you did not enable mod_rewrite in apache (which is kind of rare these days)
04.11.2017 / 18:56