我想保留我的博客在子文件夹domain_com/htdocs/blog并访问它使用blog.domain.com。 我可以使用Apache的mod_rewrite获取它:
RewriteEngine On RewriteBase / RewriteCond %{HTTP_HOST} ^blog\.domain\.com RewriteCond %{HTTP_HOST} !^/blog RewriteRule ^(.*)$ /blog/$1 [L]
但是我也想把hxxp://domain.com/blogredirect到hxxp://blog.domain.com(只是因为我想把它从用户中隐藏起来)。 简单的redirect如:
RewriteCond %{HTTP_HOST} ^wojtyniak\.com$ RewriteRule %{REQUEST_URI} ^/foo RewriteRule ^(.*)$ http://foo.wojtyniak.com [L,R=301]
导致redirect循环。 有什么办法可以在没有循环的情况下进行这样的redirect吗? 十分感谢!
PS。 对不起,对于那些hxxp的东西,但serverfault认为这些链接,并不允许我发布多个。
最理想的解决scheme是将其放在虚拟主机上,将博客文件托pipe在htdocs目录之外的某个位置。
我将假定你将无法进行这些必要的更改,但是如果你这样做, 这里是它的文档 。
是的我知道。 2年后,没有人会再需要这个了。 但也许有人被Googleredirect到这里
# Rewrite <subdomain>.example.com/<path> to example.com/<subdomain>/<path> # # Skip rewrite if no hostname or if subdomain is www RewriteCond %{HTTP_HOST} . RewriteCond %{HTTP_HOST} !^www\. [NC] # Extract (required) subdomain (%1), and first path element (%3), discard port number if present (%2) RewriteCond %{HTTP_HOST}<>%{REQUEST_URI} ^([^.]+)\.example\.com(:80)?<>/([^/]*) [NC] # Rewrite only when subdomain not equal to first path element (prevents mod_rewrite recursion) RewriteCond %1<>%3 !^(.*)<>\1$ [NC] # Rewrite to /subdomain/path RewriteRule ^(.*) /%1/$1 [L]
#