2011-01-31 135 views
1

我使用Apache和.htaccess文件來設置一些重定向。有沒有辦法將301域中的所有內容重定向到子域,除之外的域索引?.htaccess重定向

所以重定向到http://domain.com/*http://sub.domain.com/*

但留下http://domain.com/它在哪裏?

如果有人能提供幫助,請提前致謝!

回答

1

單重寫規則:

# Rewrite if on main domain AND NOT requesting index 
RewriteCond %{HTTP_HOST} ^domain[.]com$ [NC] 
RewriteCond %{REQUEST_URI} !^(/(index[.](html|php))?)?$ 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ http://sub.%1$1 [R=301,QSA,L] 
+0

這看起來像它應該以最簡潔的方式做的工作 - 我將測試一旦新domain.com頁面是內置,讓你知道。謝謝! – mrappleton 2011-02-02 10:45:15

0
# Check for non-empty request URI 
RewriteCond %{REQUEST_URI} (.+) 
RewriteRule .* http://sub.domain.com%1 [L,R=301] 
0

您可能想要允許在您的主域上使用默認的html或php。在這種情況下,下面的一對規則應該起作用。測試並確認。

# Skip the rewrite for the root of domain.com 
RewriteCond %{HTTP_HOST} ^domain[.]com$ [NC] 
RewriteCond %{REQUEST_URI} ^(/(index[.](html|php))?)?$ 
RewriteRule ^(.*)$ - [L] 

# Rewrite everything else 
RewriteCond %{HTTP_HOST} ^(domain[.]com)$ [NC] 
RewriteRule ^(.*)$ http://sub.%1$1 [R=301,QSA,L]