Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I have content on subdomain1.mydomain.com which can't reside on mydomain.com/subdomain1. Nevertheless, all my other content resides in folders of the mydomain.com/subdomain* type.

For the sake of consistency, I'd like the content actually located at subdomain1.mydomain.com to appear as if it were on mydomain.com/subdomain1 — Is there any way, using .htaccess, that I can achieve this, bearing in mind that:

(1) the subdomain itself also has a nested permalink structure, meaning that there are additional folders in the directory structure of the subdomain;

(2) I want the browser to display the address as mydomain/subdomain1 after the redirect.

share|improve this question

migrated from stackoverflow.com Apr 13 '10 at 21:56

This question came from our site for professional and enthusiast programmers.

Because of the reference to .htaccess, I assumed it is Apache and I retagged accordingly. –  bortzmeyer Apr 14 '10 at 9:53
The question is far too vague: is it static files on the disk or some sort of CMS and, if so, which one? –  bortzmeyer Apr 14 '10 at 9:54

1 Answer 1

Not sure why this has a DNS tag. DNS will not do what you want. DNS is designed to resolve host name to an ip address (A record) and vice versa (PTR record). It can also point one hostname to another hostname, and this is called a CNAME record.

As far as redirecting subdomain1.domain.com to domain.com/subdomain1

try something like this

RewriteEngine On
RewriteCond    %{HTTP_HOST} ^subdomain1\.
RewriteRule    /(.*) http://www.domain.com/subdomain1/$1 [R=301,L]
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.