2013-01-15 74 views
1

以外的子域我試圖重定向到一個子域的所有流量。國防部重寫 - 重定向到除某些URL(codeigniter)

www.example.com,example.com,sub.othersite.com 全部重寫sub.othersite.com

它的偉大工程。現在我需要排除一個URL重定向到子域

因此,如果www.example.com/THE/URI進來,我想mod重寫忽略子域重寫並將其發送到主域。

似乎很簡單,但我無法得到它的工作,因爲我有一個額外的重寫,確保所有域(有幾個停放的)以及漏斗到一個單一的域來傳遞內容。

我有一些其他的重寫條件。他們都列在這裏。如果有人能在正確的方向指向我 - 我需要基本上做到這一點:

如果傳入的請求是/的/ URI 然後去www.example.com/THE/URI 否則 重寫子。 othersite.com

<IfModule mod_rewrite.c> 
    RewriteEngine On 
    RewriteBase/

    # ignore system folder 
    RewriteCond %{REQUEST_URI} ^system.* 
    RewriteCond $1 !^(client/*) 
    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 
    RewriteCond $1 !^(index\.php|images|robots\.txt|css) 
    RewriteRule ^(.*)$ index.php?/$1 [L] 

    # if it is the SPECIAL URI redirect and EXIT 
    RewriteCond $1 !^(/THE/URI) 
    RewriteCond %{HTTP_HOST} !^www.example.com$ 
    RewriteRule ^(.*)$ http://www.example.com/THE/URI [L] 

    #catch all other traffic   
    RewriteCond %{HTTP_HOST} !^example.anothersite.com$ 
    RewriteRule ^(.*)$ http://example.anothersite.us/$1 


</IfModule> 

回答

1

已解決。 答案很簡單。我只需要從最終重寫中排除URI和QUERY_STRING,因爲重寫的上半部分會將URL添加一個查詢字符串。

爲了讓我的應用程序的工作,我仍然需要初始重寫(採取任何URI並在內部將其映射到index.php URI?)

最終代碼:

<IfModule mod_rewrite.c> 
     RewriteEngine On 
     RewriteBase/

     #Removes access to the system folder by users. 
     RewriteCond %{REQUEST_URI} ^system.* 
     RewriteCond $1 !^(client/*) 
     RewriteRule ^(.*)$ /index.php?/$1 [L] 

       # our URL is prepped now - query string appended, so let's redirect it 
       # ONLY if it's not the ONE URL we need to keep 

     RewriteCond %{REQUEST_URI} !^/THE/URI 
     RewriteCond %{QUERY_STRING} !^/THE/URI 
     RewriteCond %{HTTP_HOST} !^sub.example.com$ 
     RewriteRule ^(.*)$ http://sub.example.com/$1 [R=302] 
</IfModule>