Report this

What is the reason for this report?

How to redirect blog.domain.com to domain.com/blog

Posted on July 26, 2015

Hello all,

I’m facing serious problems to figure out how to redirect a subdomain to my primary domain. Specifically I want al requests under blog.mydomain.com to redirect to mydomain.com/blog On my Ubuntu 14.04 I have created a Vhost and inside the document root I have added a .htaccess file with the following directive:

# Various rewrite rules.
<IfModule mod_rewrite.c>
  RewriteEngine on
  RewriteCond %{HTTP_HOST} ^blog.mydomain.com [NC]
  RewriteRule ^(.*)$ http://mydomain.com/blog/$1 [R=301,L]
</IfModule>

I also tried the above directive directly in apache2.conf file but with no result. When I try to go to the blog.mydomain.com url I get the Apache2 Ubuntu Default Page

In my DNS records I have A — mydomain — droplet IP A — @ — droplet IP A — * — droplet IP CNAME — www — mydomain.

I Probably don’t need the * A record but after so many suggestions and attempts I’ve lost track of what should and shouldn’t be there.

I would like to set it up directly on Apache instead of using .htaccess but any suggestion/help would be highly appreciated.



This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

This question was answered by @jesin:

@proko Clear everything in the second virtual host and try this:

<VirtualHost *:80>
   ServerName blog.mydomain.com
   Redirect "/" "http://mydomain.com/blog/"
</VirtualHost>

View the original comment

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.