我使用Apache和.htaccess文件来设置一些重定向。有没有办法将301域中的所有内容重定向到子域,除之外的域索引?.htaccess重定向
所以重定向到http://domain.com/*
http://sub.domain.com/*
但留下http://domain.com/
它在哪里?
如果有人能提供帮助,请提前致谢!
我使用Apache和.htaccess文件来设置一些重定向。有没有办法将301域中的所有内容重定向到子域,除之外的域索引?.htaccess重定向
所以重定向到http://domain.com/*
http://sub.domain.com/*
但留下http://domain.com/
它在哪里?
如果有人能提供帮助,请提前致谢!
单重写规则:
# 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]
# Check for non-empty request URI
RewriteCond %{REQUEST_URI} (.+)
RewriteRule .* http://sub.domain.com%1 [L,R=301]
您可能想要允许在您的主域上使用默认的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]
这看起来像它应该以最简洁的方式做的工作 - 我将测试一旦新domain.com页面是内置,让你知道。谢谢! – mrappleton 2011-02-02 10:45:15