2010-02-12 82 views
1

我有一個子文件夾中的CakePHP安裝在我的服務器,我想安裝一個子文件夾內的另一個應用:的CakePHP的.htaccess mod_rewrite設定排除特定文件夾/ URL

root/public_html/subfolder/cake/ 
root/public_html/subfolder/app/ 

等。現在我需要自定義應用程序安裝有:

root/public_html/subfolder/my_custom_application/ 

我有這樣的事情在我的.htaccess:

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

如何配置它以從該規則中排除「my_custom_application」文件夾?

我嘗試這樣做:

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

但我得到這樣的:提前

Error: The requested address '/y_custom_application' was not found on this server. 

感謝。

Mauricio。在RewriteRule行之前

回答

4

如何從CakePHP的路由排除目錄:

我遇到同樣的問題,因爲你。我掙扎着,但終於找到了一些工作。
(我回復是因爲上面的答案對我沒有用,但是這樣做)。

我的目錄結構:

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

我加入到CakePHP的默認路由是什麼:

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

實際上,我需要讓人們單獨訪問子文件夾(因爲有一個單獨的應用程序)。另外,就我而言,我在默認情況下從根目錄爲CakePHP應用程序提供服務。
因此,這裏是我的CakePHP的2.x的htaccess的樣子:

更新的.htaccess(這爲我的作品)

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

在你的情況,我知道你需要這個子文件夾的工作;這裏是我的調整htaccess的我沒有機會測試這一點,但我相信這(或者相近)將工作:

(一個子文件夾)

<IfModule mod_rewrite.c> 
    RewriteEngine on 
    RewriteCond %{REQUEST_URI} !^/subfolder/directory_to_exclude/(.*) 
    RewriteRule ^$ subfolder/app/webroot/ [L] 
    RewriteRule (.*) subfolder/app/webroot/$1 [L] 
</IfModule> 
+0

它似乎工作。但不能在CakePHP 3.x中工作,請給我一些建議。 –

2

把這個:

RewriteCond %{REQUEST_URI} !^/my_custom_application 
+0

您好,感謝您的提示,但我仍然有同樣的錯誤: 錯誤:在此服務器上找不到請求的地址'/ my_custom_application'。 這次與「my_custom_application」的「m」 – Mauricio

+0

然後該規則正常工作。問題在別處。 –

0

你有最終產品用您的dir名稱替換dir_to_exclude。

<IfModule mod_rewrite.c> 
    RewriteEngine on 
    RewriteCond %{REQUEST_URI} !^/(?:dir_to_exclude)(?:$|/) 
    RewriteRule ^$ app/webroot/ [L] 
    RewriteCond %{REQUEST_URI} !^/(?:dir_to_exclude)(?:$|/) 
    RewriteRule (.*) app/webroot/$1 [L] 
</IfModule> 

如果你想有一個以上的排除目錄必須添加它們隔開| additional_dir_to_exclude

<IfModule mod_rewrite.c> 
    RewriteEngine on 
    RewriteCond %{REQUEST_URI} !^/(?:dir_to_exclude|additional_dir_to_exclude)(?:$|/) 
    RewriteRule ^$ app/webroot/ [L] 
    RewriteCond %{REQUEST_URI} !^/(?:dir_to_exclude|additional_dir_to_exclude)(?:$|/) 
    RewriteRule (.*) app/webroot/$1 [L] 
</IfModule> 
相關問題