1

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?

3 Answers 3

1

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.

1
  • correct, missed that, I have concentrated on the end, not on the beginning :) Nov 14, 2009 at 11:23
1

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

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

Thanks all!

0

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]

3
  • 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.
    – Parag
    Nov 13, 2009 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"?
    – Parag
    Nov 13, 2009 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 Nov 14, 2009 at 11:25

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .