2010-03-31 19 views
0

目前我正在使用包含在我的域的子目錄中的CodeIgniter創建一個項目。在這個例子中,我們將其稱爲domain.com/test。在一個站點上多個Mod_ReWrites - 可能嗎? (在根目錄中的WordPress博客,子目錄中的CodeIgniter項目)

我也有Wordpress安裝在這個域上,它的所有文件都在根目錄下。例如,如果您導航到我的domain.com,那麼它會拉起Wordpress博客。我目前已經激活了WordPress的mod_rewrite,因此它使用友好的URL。

對於那些不熟悉CodeIgniter的人來說,所有請求都通過項目根文件夾中的index.php路由。所以,在這種情況下,它會是domain.com/text/index.php。對應用程序的請求將發送,如domain.com/test/index.php/somecontroller/method。

我想要做的是針對任何傳入的請求,這些請求是針對/ test /文件夾或其中的某個子目錄,我希望它適當地重寫URL以便index.php不包含在內。 (根據上面的例子,它最終將成爲domain.com/test/somecontroller/method)

對於任何其他請求,意味着任何不在/ test /目錄中,我希望它路由請求Wordpress。

我會想象它是一個簡單的RewriteCond,使它能夠檢查請求是針對/ test /目錄還是其中的一個子目錄,但我不知道該怎麼做。也許你不能在每個站點有多組重寫規則。

我將爲每個應用程序包含推薦的mod_rewrite規則。

的WordPress:(目前使用)

<IfModule mod_rewrite.c> 
    RewriteEngine On 
    RewriteBase/
    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteRule . /index.php [L] 
</IfModule> 

笨:(從Wiki拉動)

<IfModule mod_rewrite.c> 
    RewriteEngine On 
    RewriteBase/

    #Removes access to the system folder by users. 
    #Additionally this will allow you to create a System.php controller, 
    #previously this would not have been possible. 
    #'system' can be replaced if you have renamed your system folder. 
    RewriteCond %{REQUEST_URI} ^system.* 
    RewriteRule ^(.*)$ /index.php?/$1 [L] 

    #When your application folder isn't in the system folder 
    #This snippet prevents user access to the application folder 
    #Submitted by: Fabdrol 
    #Rename 'application' to your applications folder name. 
    RewriteCond %{REQUEST_URI} ^application.* 
    RewriteRule ^(.*)$ /index.php?/$1 [L] 

    #Checks to see if the user is attempting to access a valid file, 
    #such as an image or css document, if this isn't true it sends the 
    #request to index.php 
    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteRule ^(.*)$ index.php?/$1 [L] 
</IfModule> 

<IfModule !mod_rewrite.c> 
    # If we don't have mod_rewrite installed, all 404's 
    # can be sent to index.php, and everything works as normal. 
    # Submitted by: ElliotHaughin 

    ErrorDocument 404 /index.php 
</IfModule> 

任何及所有的幫助深表感謝!

感謝,

-Sootah

+0

顯然,我真正要做的是的.htaccess添加到/測試/子目錄和規則包含在其內表面上覆蓋父目錄的規則。 但是,我仍然想知道這是否可以在一個.htaccess中實現。 – Sootah 2010-03-31 04:05:12

+0

您需要單獨的.htaccess文件,因爲如果用戶正在進入測試目錄,根目錄中的.htaccess將不會被看到,因此其'指令被忽略... – stormdrain 2010-03-31 14:04:03

回答

1

@Myself和Stormdrain - 正如上面我的評論說(和Stormdrain在闡述),簡單地把笨的.htaccess在/測試/子目錄的伎倆。

啊,我也應該注意到,我也必須從這個修改笨的.htaccess基本路徑線: RewriteBase/

這樣: RewriteBase /測試/

希望這有助於別人說有相同/相似的問題。

- Sootah

相關問題