CakePHP .htaccess mod_rewrite configuration to exclude a particular folder/url

后端 未结 3 2025
半阙折子戏
半阙折子戏 2020-12-22 01:48

I have a CakePHP installation in a sub folder in my server, I want to install another application inside that subfolder:

root/public_html/subfolder/cake/
roo         


        
3条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-22 01:59

    How to Exclude a Directory from CakePHP Routing:

    I ran into the same problem as you. I struggled, but finally found something that worked.
    (I'm replying because the answer above didn't work for me, but this did).

    My directory structure:

    root/public_html/app/
    root/public_html/lib/
    root/public_html/plugins/
    root/public_html/vendors/
    root/public_html/directory_to_exclude/
    

    What I added to CakePHP's default routing:

    RewriteCond %{REQUEST_URI} !^/directory_to_exclude/(.*)
    

    Effectively, I needed to allow people to access the subfolder separately (since that has a separate application). Also, in my case, I'm serving a CakePHP application by default from the root directory.
    So here's what my CakePHP 2.x htaccess looks like:

    Updated .Htaccess (this works for me)

    
       RewriteEngine on
       RewriteCond %{REQUEST_URI} !^/directory_to_exclude/(.*)
       RewriteRule    ^$ app/webroot/    [L]
       RewriteRule    (.*) app/webroot/$1 [L]
    
    

    In your case, I understand you need this to work in a subfolder; here's my adjusted htaccess I didn't have a chance to test this, but I believe this (or something close) will work:

    The Final Product (for a subfolder)

    
       RewriteEngine on
       RewriteCond %{REQUEST_URI} !^/subfolder/directory_to_exclude/(.*)
       RewriteRule    ^$ subfolder/app/webroot/    [L]
       RewriteRule    (.*) subfolder/app/webroot/$1 [L]
    
    

提交回复
热议问题