2012-01-11 39 views
0

我經歷了很多其他的「兩個域,一個服務器」問題的看了看,並沒有看到什麼我正在尋找...兩個域,1個共享服務器,.htaccess文件

我有兩個域,www.example1.com和www.example2.com。他們與apache共享主機環境。我想:

A)example1.com只加載正常index.html文件(在安裝WordPress) B)example2.com去到子文件夾/論壇/

所以,換句話說,我希望example1.com成爲我的主要(正常和快樂)域和example2.com只加載/論壇/目錄。

我在想我可能只需要重寫一個example2.com去/ forums /的規則?

我希望這是有道理的:)。非常感謝您提供的任何幫助。

回答

0

嘗試將以下內容添加到您的域的根文件夾中的htaccess文件中。

RewriteEngine on 
RewriteBase/

#if on www.example1.com domain 
RewriteCond %{HTTP_HOST} ^www\.example1\.com$ [NC] 
#and not an existing file of directory 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
#then send all requests to index.php 
RewriteRule^index.php [L] 


#if on www.example2.com domain 
RewriteCond %{HTTP_HOST} ^www\.example2\.com$ [NC] 
#if not already in forums directory 
RewriteCond %{REQUEST_URI} !/forums/ [NC] 
#rewrite requests to forums directory 
RewriteRule (.*) forums/$1 [L] 
+0

感謝這麼多的快速回復! 使用你的代碼,example1.com確實加載index.php就好了。 但是,當example2.com加載時,我得到一個404錯誤。 任何想法? – 2012-01-12 23:38:40

+0

Ooops,我的意思是一個500內部服務器錯誤(不是404)。 – 2012-01-12 23:46:15

+0

@JeremySchubert我忘了一個條件:見上面編輯 – 2012-01-13 01:02:40

0

也許這對某人有用。掃描並嘗試各種方法後,似乎完美的工作。我正在使用Apache服務器。在我的htaccess文件中,在IfModule之後,我添加了<If>條件並且工作正常。

<IfModule> 
. 
. 
    RewriteRule ^$ webroot/ [L] 
    RewriteRule (.*) webroot/$1 [L] 
</IfModule> 
<If "%{HTTP_HOST} == 'www.xyzs.co.uk'"> 

    Redirect permanent /xyz1 /yyy1 
    Redirect permanent /xyz2 /yyy2 
    Redirect permanent /xyz3 /yyy3 
    Redirect permanent /xyz4 /yyy4 
<If> 

更多閱讀:http://httpd.apache.org/docs/2.4/expr.html

相關問題