2014-09-13 60 views
0
Options +FollowSymLinks -MultiViews 
RewriteEngine on 
RewriteBase/
RewriteCond %{HTTP_HOST} !www.getshoutbox.com$ [NC] 
RewriteCond %{HTTP_HOST} ^(.*)\.getshoutbox\.com 
RewriteRule ^(.*)$ http://www.getshoutbox.com/test.php?id=%1 [L,NC] 

這些規則做工精細,除了我被重定向到:如何防止重定向.htaccess規則重寫?

http://www.getshoutbox.com/test.php?id=X 

如何恢復這一點,留在:

http://X.getshoutbox.com 

回答

1

問題與您的規則是,你正在使用的全域用WWW代替只是在內部重定向它:

Options +FollowSymLinks -MultiViews 

RewriteEngine on 
RewriteBase/

# do nothing avoid loop 
RewriteRule ^test.php$ - [L] 

# if domain is not www.yourdomain.com or yourdomain.com 
RewriteCond %{HTTP_HOST} !^(www\.)?getshoutbox\.com$ [NC] 
# then get the subdomain with ([^\.]+)?\.yourdomain.com 
RewriteCond %{HTTP_HOST} ^([^\.]+)?\.getshoutbox\.com$ [NC] 
# use the result below 
RewriteRule^test.php?id=%1 [NC,L] 

由於我們已經知道我們不在www.yourdomain.comyourdomain.com上,因此捕獲子域並使用%1作爲id將其傳遞下來,並刪除http://www.getshoutbox.com/,因爲在這種情況下它不是必需的。