5

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!

Book Of Zeus
  • 49,509
  • 18
  • 174
  • 171

1 Answers1

4

use this:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^blog\.domain\.com [NC]
RewriteRule (.*) http://domain.com/blog/$1 [R=301,L]
Book Of Zeus
  • 49,509
  • 18
  • 174
  • 171
  • 1
    you should escape dots in regexp: `RewriteCond %{HTTP_HOST} ^blog\.domain\.com$ [NC]` – Seybsen Oct 26 '11 at 08:47
  • Thanks for both of your responses. I've tried the original idea and then replaced the 2nd line with Seybsen's RewriteCond but no luck. Can you think of a reason that when I go to http://blog.domain.com that there is no action taken and it just sits at http://blog.domain.com? – user1013465 Oct 28 '11 at 01:43
  • is the .htaccess with this config file in the www.domain.com folder? where is the blog. and www. points to (which folders)? – Book Of Zeus Oct 28 '11 at 01:45