开发者

Rewrite URL to subfolder with multiple APPs

I have multiple CakePHP Projects hosted on same domain and some randoms folders with randons files, for organize I separated APPs on folder, but I have the "main" app that are in site folder, when user access domain it should rewrite URL to /site, my problems are with randoms folders, when I try access domain.com/exist_folder it redirect me to /site.

I dont want to rewrite if file/directory exist on server.

Example of FTP Tree

public_html/
 -cakephp (CakePHP Core)/
   - ...
 -site (CakePHP App)/
   - ...
   -.htaccess
   -webroot/
     -.htaccess
 -exist_folder/
   - whateverfiles.ext
 -app1 (CakePHP App)/
   - ...
   -.htaccess
   -webroot/
     -.htaccess
 -folder1/
 -temp/
   -images
   -videos
 -.htaccess

My .htaccess

public_html/.htaccess

<IfModule mod_rewrite.c>
    RewriteEngine on
    R开发者_如何转开发ewriteCond %{REQUEST_FILENAME} -f [OR]
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule    ^$    site/    [L]
    RewriteRule    (.*) site/$1    [L]
</IfModule>

site/.htaccess AND app1/.htaccess

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

site/webroot/.htaccess AND app1/webroot/.htaccess

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
</IfModule>


So basically you have some folders which you don't want to pass through Cake's routing and dispatcher. For this, add the following lines in your public_html/.htacess file:

RewriteRule   ^(exist_folder).* - [NC,L]

This will allow direct access to the exist_folder which is in root directory. Accessing http://domain.com/exist_folder would be possible after adding this rule.

If you are looking for an automated solution (Your lines: I dont want to rewrite if file/directory exist on server), create a php file which will generate a .htaccess file with above mentioned RewriteRule basing on is_dir(). Whenever you add a folder, run this php file which'll generate a .htaccess with all the exceptions added :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜