Apache rewrite from subdomain to www but keep all permalinks

北城以北 提交于 2019-12-23 11:48:32

问题


I've researched this for about 2 hours now and although most of the topics are similar, none have explained how to do what I'd like to do.

I'm taking a blog that had a structure of blog.domain.com and moving it to www.domain.com/blog/. I need to keep the permalink of the blog post when I redirect so...

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

should become:

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

After trying many things, this is the last thing I tried which ends up having no affect at all. Meaning blog.domain.com just sits at blog.domain.com/

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

Here's the entry from my httpd.conf file.

<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>

Can anyone help?

Thanks!


回答1:


use this:

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


来源:https://stackoverflow.com/questions/7895637/apache-rewrite-from-subdomain-to-www-but-keep-all-permalinks

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!