Forum Moderators: phranque

Message Too Old, No Replies

Apache redirect url problem

         

modhu7

5:02 am on Nov 4, 2008 (gmt 0)

10+ Year Member



Suppose, I've a domain named domain.com. Now I want it to redirect the following url as:
cat.domain.com -------------> www.domain.com/cat
dog.domain.com -------------> www.domain.com/dog
james.domain.com -----------> www.domain.com/james

Anyone can help? Please..........

paulororke

6:31 pm on Nov 6, 2008 (gmt 0)

10+ Year Member



I'm pretty new at this myself but one way, perhaps not the slickest, might be to use name based virtual hosts
[httpd.apache.org...] and make the document root for each site the subfolders you suggested.

paulororke

6:35 pm on Nov 6, 2008 (gmt 0)

10+ Year Member



Sorry - I should have looked further, this is a common problem it seems. Look at this post where the same question is asked: [webmasterworld.com...]

modhu7

3:58 am on Nov 7, 2008 (gmt 0)

10+ Year Member



Thanks paulororke...........
I found a solution.
I used rewrite rule in .htaccess file.
Those are something like the following:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^cat\.domain\.com$
RewriteRule (.*) [domain.com...] [p] ## You must have the proxy module enabled

RewriteCond %{HTTP_HOST} ^dog\.domain\.com$
RewriteRule (.*) [domain.com...] [p]

g1smd

1:14 pm on Nov 9, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Do you need to redirect or rewrite?

Be very clear as to the difference before you answer the question...

modhu7

1:57 pm on Nov 9, 2008 (gmt 0)

10+ Year Member



@g1smd, sorry if my question/solution is incorrect, actually i was looking for a proxy based solution, before finding out the proxy pass way, i solved the problem using rewrite.

g1smd

2:21 pm on Nov 9, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



If they are subdomains on the same domain, then a rewrite can work.

If it is cross-domain, then I think proxy might be the only way; but I am no expert.

jdMorgan

2:42 pm on Nov 9, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The code posted above has a bad side-effect not at all related to it's desired function: Putting the comment on the same line as the code will cause an Apache Warning to be logged for every HTTP request to the server. That's a huge waste of server resources...

Don't put a comment on the same line as a directive -- Move the comment to a separate line above the directive.

Jim