Hide domain directory using htaccess or cakephp router

Asked

Viewed 1,829 times

3

I am having trouble creating a setup on . htaccess to hide a folder from my site.

My domain has the following structure: www.site.com.br/cake , where are the files and folders referring to the project. 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]
</IfModule>

I’ve tried to:

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 help me?

  • It is best to move the cake folder to a level above the publish folder, /home/cakephp/, that is to say without direct access, since you can move wherever you want the webroot folder, and even rename it, after that, just set the path in the define constant('ROOT', dirname(dirname(dirname(FILE)))); which is in the index.php of this public folder, pointing to /home/cakephp/

  • Good evening, I wonder if the answer helped you, if not please comment on what you think is missing.

1 answer

2

What you want is not to necessarily hide the directory, but to direct the access from the root folder to from 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]
</IfModule>

If error 500 is happening it is likely that you have not enabled modrewrite, for this open 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.

  • Oops, I removed # from Loadmodule but still error 500

  • Hi @Kevin. F, did you restart Apache? There’s something else in your htaccess?

  • Yes has some other rewrite, and already restarts apache.

  • @Kevin. F formulates a question and posts the whole mod_rewrite please, then sends me the link

  • follow my question https://answall.com/questions/203591/occur-direct%C3%B3rio-de-domain-using-htaccess

Browser other questions tagged

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