Apache从子域重写为www,但保留所有永久链接

时间:2011-10-25 20:46:50

标签: apache .htaccess redirect subdomain permalinks

我现在已经研究了大约2个小时,虽然大部分主题都很相似,但没有人解释过如何做我想做的事。

我正在使用blog.domain.com结构的博客并将其移至www.domain.com/blog/。当我重定向时,我需要保留博客文章的永久链接......

blog.domain.com/here-is-a-blog-post/

应该成为:

www.domain.com/blog/here-is-a-blog-post/

在尝试了很多事情之后,这是我尝试的最后一件事,最终完全没有任何影响。意思是blog.domain.com只是位于blog.domain.com /

RewriteEngine on
RewriteCond %{HTTP_HOST} ^xyz\.domain\.com$
RewriteRule ^/(.*) http://domain.com/$1 [redirect,last]

这是我的httpd.conf文件中的条目。

<VirtualHost xxx.xxx.xxx.xxx:80>
    SSLEngine off
    SuexecUserGroup apache apache
    ServerName      www.domain.com
    ServerAlias     domain.com
    ServerAlias     blog.domain.com
    ServerAdmin    webmaster@domain.wiredground.com
    DocumentRoot   /home/domain/www/domain.wiredground.com
    ScriptAlias    /cgi-bin/ "/home/domain/www/cgi-bin/"
    <Directory /home/domain/www/cgi-bin>
        AllowOverride None
        Options ExecCGI
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>

有人可以帮忙吗?

谢谢!

1 个答案:

答案 0 :(得分:4)

使用它:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^blog\.domain\.com [NC]
RewriteRule (.*) http://domain.com/blog/$1 [R=301,L]