Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apache rewrite from subdomain to www but keep all permalinks

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    [email protected]
    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!

like image 388
user1013465 Avatar asked Oct 09 '22 16:10

user1013465


1 Answers

use this:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^blog\.domain\.com [NC]
RewriteRule (.*) http://domain.com/blog/$1 [R=301,L]
like image 57
Book Of Zeus Avatar answered Oct 18 '22 00:10

Book Of Zeus