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

I was using Droplr with my domain, 'example.com', prepended with 'u.'. (u.example.com). The prepend was not a subdomain, and would redirect to Droplr via an A record to their server's IP Address.

Edit ---

In other words, I didn't create u.example.com as a subdomain of example.com, but rather created an A record to make it act like a subdomain.

However, I changed the domain being used with Droplr to example.com from u.example.com, and I am trying to setup a redirect with .htaccess to forward any requests to u.example.com/abcd to example.com/abcd.

I currently have the following, but it doesn't seem to have any affect on the domain. Please can you tell me where I am going wrong?

RewriteEngine on
RewriteCond %{HTTP_HOST} ^u.example.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.u.example.com$
RewriteRule ^(.*)$ http://example.com/$1 [R=301,L]
share|improve this question
    
It might be because its saturday and I haven't had coffee, but this question makes no sense (among other things, u.example.com is by definition a subdomain of example.com). I think you may just have your terminology tied up in a marvelous knot (confused between subdomain and virtual host?) -- can you clarify a little bit? –  voretaq7 Nov 10 '12 at 19:06
    
@voretaq7 Does that make a bit more sense? –  max_ Nov 10 '12 at 19:08
    
Yes, much more :-) And Kamil's answer below is the easiest solution (avoid the headache of mod_rewrite entirely wherever possible :-) -- If you want to do it with rewrite rules you can, its just more work -- this question can point you in the right direction –  voretaq7 Nov 10 '12 at 19:12
    
@voretaq7 I think that htaccess is actually the only way as I'm on shared hosting... –  max_ Nov 10 '12 at 19:19
add comment

1 Answer 1

Setup virtual domain u.example.com with alias www.u.example.com and inside the virtual server configuration do permanent redirect.

You don't need mod_rewrite, it's unnecessarily complicated and demanding.

In case you have "wildcard" hosting for entire *.example.com you can use following rules to normalize your URIs:

RewriteEngine on
RewriteCond %{HTTP_HOST} =u.example.com [OR]
RewriteCond %{HTTP_HOST} =www.u.example.com
RewriteRule ^(.*)$ http://www.example.com/$1 [R=permanent,L]
share|improve this answer
    
I don't have access to setting up a virtual domain as I'm on shared hosting –  max_ Nov 10 '12 at 19:19
    
If you're on shared hosting you're probably better off talking to your provider - they may have other restrictions in place that would cause you trouble... –  voretaq7 Nov 10 '12 at 19:21
    
Hmm, that's a good point. Is there any other way in which I could do this without having to go through virtual domains? –  max_ Nov 10 '12 at 19:23
    
@iBeProgrammer and are you sure, the request ends in your current hosting? If so, see my edited answer –  Kamil Šrot Nov 10 '12 at 19:25
add comment

Your Answer

 
discard

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.