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.

Heres the situation: I have a couple of different web projects running on a single shared host. Project 'A' is accessed through a subdomain (subA.mydomain.com) while project 'B' is the main mydomain.com

Both A and B are symlinks inside the host's public_html folder:

ln -s /home/myhost/ProjectA ~/public_html/subA
ln -s /home/myhost/ProjectB ~/public_html/main

The subdomain (project A) works fine and the site is running on it. For 'B' which is the main domain, i have used .htaccess to point primary domain to a subfolder as written here. The domain website is also working fine.

The problem is when i do mydomain.com/subA, the subdomain website (project A) opens. I tried adding redirect rules to point mydomain.com/subA --> subA.mydomain.com like so:

RewriteCond %{HTTP_HOST} ^mydomain.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.mydomain.com$
RewriteRule ^subA\/?$ "http\:\/\/subA\.mydomain\.com\/" [R=301,L]

But the url still reads mydomain.com/subA and the website shown is project A (with images and static files missing obviously as its a different web project).

Why isn't the redirect working?

share|improve this question

3 Answers 3

Unless you have a RewriteBase / somewhere, ^subA\/?$ isn't going to match anything. Mod_rewrite looks at the entire url, including the leading /. Try:

RewriteRule ^/subA/?$ http://subA.mydomain.com/ [R=301,L]

Also, you can loosen up on the escaping. It doesn't hurt, but it also doesn't help anything, and it makes it harder to read.

share|improve this answer
    
correct, missed that, I have concentrated on the end, not on the beginning :) –  Aleksandar Ivanisevic Nov 14 '09 at 11:23
up vote 1 down vote accepted

It seems the following line worked (and remove the earlier regex-heavy redirection code):

RedirectMatch 301 /subA/ http://subA.mydomain.com/

Thanks all!

share|improve this answer

request URI for mydomain.com/subA is /subA (note no trailing slash) which will not match

change your rewrite rule to

RewriteRule ^subA http://subA.mydomain.com/ [R=301,L]

share|improve this answer
    
hmmm...its not working. If i type "mydomain.com/subA" or "mydomain.com/subA/", the resulting url is still "mydomain.com/subA/". And i dont have anything else in htaccess besides what i mentioned in the question. –  fenderplayer Nov 13 '09 at 20:38
    
Does it matter if theres an index.php file in "subA" (i'm using frameworks), as in "/home/myhost/ProjectA/index.php"? –  fenderplayer Nov 13 '09 at 20:42
    
Should be RewriteRule ^/subA subA.mydomain.com [R=301,L], see the answer below if it still doesnt work add RewriteLog /tmp/rewrite.log RewriteLogLevel 9 and post the contents of rewrite.log –  Aleksandar Ivanisevic Nov 14 '09 at 11:25

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.