2013-11-15 95 views
1

我有一個subdomian設置,我想指向特定的目錄。如何將子域根映射到域文件夾

cdn.domain.com 

我想cdn.domain.com指向domain.com/wp-content/,但不是作爲一個重定向,因爲這將只顯示cdn.domain.com/wp-content/

我想設置域根目錄,這樣當我寫cdn.domain.com它將顯示位於domain.com/wp-content/的文件。

有沒有人有關於我如何做到這一點的想法?

+0

是域/子域在同一臺服務器上並共享相同的文檔根? –

+0

@JonLin是的,他們是,他們做:) – iamchriswick

回答

0

我設法用.htaccess文件中的下列代碼完成我想完成的任務。 :)

# Rewrite all requests for wp-content from cdn, so they are fetched from the right place 
RewriteCond %{HTTP_HOST} ^cdn\.responseretail\.no 

# Prevent an endless loop frm ever happening 

RewriteCond %{REQUEST_URI} !^/wp-content 
RewriteRule (.+) /wp-content/$1 [L] 

# Redirect http://cdn.domian.com/ to the main page (in case a user tries it) 
RewriteCond %{HTTP_HOST} ^cdn\.domain\.com 
RewriteRule ^$ http://www.domain.com/ [R=301,L]