2012-01-11 75 views
0

比方說,我的根域名是main.com和我有兩個插件域:addon1.comaddon2.com多個插件域,一個htaccess文件

我的劇本是早就準備好了,我可以看到我的網站是這樣的:

www.main.com/show.php?domain=addon1.com 

但是,我希望通過自己的域上顯示的網站內容。我的意思是當我打開addon1.com時,我想看到輸出爲show.php?domain = addon1.com。同時這兩個域添加附加域和其目錄是:

main.com/addon1.com/ 
    main.com/addon2.com/ 

我寫了一htaccess文件的根文件夾(main.com/.htaccess)

Options +FollowSymLinks 
    RewriteEngine On 

    RewriteCond %{HTTP_HOST} ^www\.addon1\.com$ [NC] 
    RewriteRule ^(.*)$ /show.php?domain=addon1.com&$1 

    RewriteCond %{HTTP_HOST} ^www\.addon2\.com$ [NC] 
    RewriteRule ^(.*)$ /show.php?domain=addon2.com&$1 

但我發現了500間隔錯誤。有什麼建議?

在此先感謝。

回答

0

您的規則正在循環。 /show.php將通過重寫引擎返回並無限循環。您需要添加的條件,使他們不循環:

RewriteCond %{HTTP_HOST} ^www\.addon1\.com$ [NC] 
RewriteCond %{REQUEST_URI} !^/show.php 
RewriteRule ^(.*)$ /show.php?domain=addon1.com&$1 

RewriteCond %{HTTP_HOST} ^www\.addon2\.com$ [NC] 
RewriteCond %{REQUEST_URI} !^/show.php 
RewriteRule ^(.*)$ /show.php?domain=addon2.com&$1 
+0

感謝您的回答。但是這是嘗試加載** main.com/addon1.com/show.php **,show.php位於根文件夾(main.com/show.php)中。 – Deniz 2012-01-11 20:53:17

0

你需要包括「RewriteBase」助陣。

# tell mod_rewrite to activate and give base for relative paths 
    Options +FollowSymLinks 
    RewriteEngine on 
    RewriteBase /

# for the active site in hosting root folder, 
# tell it not to look for a subfolder by skipping next rule 
    RewriteCond %{HTTP_HOST} ^(www\.)?main\.com [NC] 
    RewriteRule ^(.*)$   - [S=1] 

# the domain-name = sub-folder automation 
# thus addon-domain.com in /addon-domain(\.com)?/ 
    RewriteCond %{HTTP_HOST} ([^.]+)\.com 
    RewriteCond %{REQUEST_URI} !^/%1 
    RewriteRule ^(.*)$   %1/$1 [L] 

# to answer your question swap the above 
# domain-name = sub-folder automation for this rule 
    RewriteCond %{HTTP_HOST} ([^.]+)\.com$ [NC] 
    RewriteCond %{REQUEST_URI} !^/show.php 
    RewriteRule ^(.*)$   /show.php?domain=%1&$1 [L] 
# although, the above line may require this instead 
    RewriteRule .    main.com/show.php?domain=%1&$1 [L]