2011-05-19 60 views
1

我有一個小問題需要解決。我有兩個並排運行的應用程序(CodeIgniter和ExpressionEngine),我需要將特定的URL模式路由到CI以及其他所有內容到EE。到目前爲止,這主要是工作,但有一個小細節。下面的代碼我目前有:與mod_rewrite只匹配一個特定模式的網址

# Rewrite requests for anything that's not a CI controller or physical file/folder to ExpressionEngine 
RewriteBase/
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond $1 !(admin|cron|fst_reporting|playcatch|ppv|purchase|reporting|xml) [NC] 
RewriteRule ^(.*)$ /index.php/$1 [L] 

# Route everything else to CodeIgniter 
RewriteBase/
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ /app/index.php/$1 [L] 

不過,我也想將任何請求:

/training 
/training/ 
/training/programme/something 
/training/programme/something/ 

第一個條件塊EE,然後強制爲一個特定的URL模式

請求
/training/something 

給CI應用程序(參見第二個條件塊)。

我正試圖融入上述要求到我現有的條件語句的問題,最好我想說「凡是不等於我的代碼點火器控制器或等於/培訓或/培訓/程序/什麼」。同時,我仍然需要能夠將請求/訓練/某物(其中某些是隨機字符串)發送到CI應用程序。

任何想法? :)

回答

2

也許是這樣的:

RewriteBase/
RewriteCond %{REQUEST_URI} ^/training(/)?(/programme/something)?(/)? [OR] 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond $1 !(admin|cron|fst_reporting|playcatch|ppv|purchase|reporting|xml) [NC] 
RewriteRule ^(.*)$ /index.php/$1 [L] 

希望幫助。

+0

嗨羅布,感謝你這個..(/ program/something)部分需要匹配一個模式,比如「/ program/MTMwfG5pbmVmb3Vy」,但同時不能匹配一個URL,比如「/ program /消防安全/培訓」。這就是我堅持的東西。 :/ – 2011-05-23 12:47:03

+0

對不起,延遲響應!試試這個大小:RewriteCond%{REQUEST_URI} ^/training(/)?(/ program /)?(?!.* training $)/?這應該匹配任何從培訓開始,可以編程,然後具有任何內容的任何內容,只要它展望未來並且看不到「培訓」即可。如果你運行的是Apache 2.x,這可能僅適用,因爲我認爲1.x不支持預覽正則表達式。我希望這個對你有用。 – 2011-05-24 12:49:04