Hide domain directory using htaccess or router in cakephp


I'm having trouble creating a configuration in .htaccess to hide a folder on my site.

My domain has the following structure: www.site.com.br/cake , where the files and folders referring to the project are. I want to hide the /cake directory, showing only the domain on all pages, www.site.com.br/

The current .htaccess file has the following configuration:

<IfModule mod_rewrite.c>
   RewriteEngine on
   RewriteRule    ^$ app/webroot/    [L]
   RewriteRule    (.*) app/webroot/$1 [L]

Already tried:

RewriteCond %{HTTP_HOST} ^(www.)?site.com.br$
RewriteCond %{REQUEST_URI} !^/cake/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /
RewriteCond %{HTTP_HOST} ^(www.)?site.com.br/$
RewriteRule ^(/)?$ cake/index.php [L]

And it doesn't work, it gives error 500. Can you help me?


What you want is not necessarily to hide the directory, but to direct access from the root folder to the cake folder.

Create the .htaccess file in the root folder and add the following content:

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

If error 500 is happening it's likely that you haven't enabled modrewrite, for that open the httpd.conf file and look for the line that contains something like:

LoadModule rewrite_module modules/mod_rewrite.so

It is likely that she is commented:

#LoadModule rewrite_module modules/mod_rewrite.so

Remove the hash (#) save the file and restart Apache.

Scroll to Top