Hide domain directory using htaccess

0

I need to hide the directory of url .

How it works:

www.meusite.com.br/Site/view/telaInicial.php

How do I:

www.meusite.com.br/telaInicial.php

My current .htaccess :

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
  

Currently my .htaccess only does this function above which has nothing to do with the question, but I do not know if it disturbs the others below

What I've tried in my .htaccess :

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]

<IfModule mod_rewrite.c>
   RewriteEngine on
   RewriteBase /
   RewriteRule ^(?!cake/)(.*)$ cake/$1 [QSA,L]
</IfModule>

But I get the 500 error.

I have already removed the hash (#) from the front of LoadModule rewrite_module modules/mod_rewrite.so in apache httpd.conf, and already restart apache and nothing.

I know you have an identical question Hide domain directory using htaccess or router in cakephp , but the answer to that was not good for me.

Image of the structure.

    
asked by anonymous 10.05.2017 / 16:16

1 answer

0

This .htaccess looks very wrong:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]

<IfModule mod_rewrite.c>
   RewriteEngine on
   RewriteBase /
   RewriteRule ^(?!cake/)(.*)$ cake/$1 [QSA,L]
</IfModule>

First you do not need 2 RewriteEngine on , depending on whether RewriteBase is more complicated, if the .htaccess is not in root then you must specify the entire path in RewriteBase , otherwise you used mod_rewrite but left rules on the outside, I'll ask you to make two attempts :

  • Remove IfModule and RewriteBase set to this:

    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(?!cake/)(.*)$ cake/$1 [QSA,L] # Redireciona para dentro da pasta cake
    
    RewriteRule ^([^\.]+)$ $1.php [NC,L] # qualquer path que não tiver . no nome tenta acessar algo com .php
    

    If this does not work, then everything may be inside the cake folder:

    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(?!cake/)(.*)$ cake/$1 [QSA,L]
    RewriteRule ^([^\.]+)$ cake/$1.php [NC,L]
    
  • If error 500 occurs, the second attempt is to add ifmodule to make sure the module is active:

    <IfModule mod_rewrite.c>
        RewriteEngine On
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteRule ^(?!cake/)(.*)$ cake/$1 [QSA,L] 
        RewriteRule ^([^\.]+)$ cake/$1.php [NC,L]
    </IfModule>
    
  • Even though the error can be caused by continuous redirects, but to be sure only to inform the structure of the folders.

        
    10.05.2017 / 18:25