Hide domain directory using htaccess

Asked

Viewed 1,441 times

0

I need to hide the directory of url.

How does it look:

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

How I need:

www.meusite.com.br/telaInicial.php

Man .htaccess currently:

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

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

What I’ve tried in mine .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 can think of error 500.

I already took the hash (#) out of the front of the 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 cakephp router but the reply of it did not serve for me.

Picture of the structure.

inserir a descrição da imagem aqui

  • Hello Kevin I did an answer, but still can not be sure, could inform the folder structure, like if cake is root or if htdocs is root and as this the structure of this specific project?

  • root is the Site folder after the other view inside etc... I have an index in the root folder that redirects to view/telaInicial.php

  • And the cake folder, is where exactly? Could you send a print to make it easier to understand?

  • There’s no cake, my structure is different. That’s how I explained it in the question.

  • Then why on Regex did it cake/$1? Could you post the folder structure please? It might even be an image.

  • Okay, follow up on the question the structure image.

Show 1 more comment

1 answer

0


This . htaccess seems 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 it is not necessary 2 RewriteEngine on, according to the use of Rewritebase is more complicated, if . htaccess is not in root then you must specify the whole path in RewriteBase, out that you used mod_rewrite but left rules outside, I’ll ask you to do two attempts:

  1. Remove the IfModule and RewriteBase fit for 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 it doesn’t work out for this, because maybe it’s all inside the folder cake:

    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(?!cake/)(.*)$ cake/$1 [QSA,L]
    RewriteRule ^([^\.]+)$ cake/$1.php [NC,L]
    
  2. 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>
    

Still the error may be caused by continuous redirects, but to be sure only to inform the folder structure.

Browser other questions tagged

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