Forum Moderators: phranque

Message Too Old, No Replies

Can mod_rewrite RewriteRule to Route Subdomain URL to Directory?

Question: mod_rewrite RewriteRule

         

BWSmith

8:18 pm on Jul 23, 2004 (gmt 0)

10+ Year Member



I have been told that mod_rewrite can be used to route any incoming traffic for subdomain.main.com to a specific directory on main.com. Is this correct?

We've used it for redirecting traffic from a directory to another web site, but I am not yet convinced that it will redirect subdomain traffic like we want it to.

The www.main.com is a live site - we just want the subdomain.main.com traffic to be redirected to /directory. Is it possible usign mod_rewrite?

jdMorgan

8:35 pm on Jul 23, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



BWSmith,

Welcome to WebmasterWorld [webmasterworld.com]!

Yes, just put code similar to that in this thread [webmasterworld.com] into an .htaccess file in the directory tree with or above the subdomain files, or do it at the server config level in httpd.conf.

Jim

BWSmith

9:31 pm on Jul 23, 2004 (gmt 0)

10+ Year Member



Jim:

Thank you for your response! I'll check out the syntax.

Unfortunately this is a web site on a server that is not ours, so editing the httpd.conf is out.

The ISP wanted to charge us for a full domain (with the full monthly fee) for forwarding subdomain.main.com to a specific directory inside main.com. I figured it would only involve a couple of lines in httpd.conf, but I couldn't talk them into seeing it that way.

Thanks again!

jdMorgan

9:55 pm on Jul 23, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



> The ISP wanted to charge us for a full domain [...]

Not good... For you or for them.

Jim

BWSmith

10:15 pm on Jul 23, 2004 (gmt 0)

10+ Year Member



Yeh - they allow "unlimited subdomains" if you want it pointed to the root directory of a web site.

If you want it pointed to a specific subdirectory, they claimed it was the same (to them) as a new domain.

Yet, they only charge $5/month for a redirect of a of domain name to another domain, so I told them this should be similarly priced and that I would pay their $5/month. Nope, according to them - it's a new domain!

And this from one of the larger ISPs in the area...

jdMorgan

12:32 am on Jul 24, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



$5 a month for two lines of code and one new A record? That's theft.

All the code you need has been posted here on WebmasterWorld, including a cool arbitrarily-named subdomain to subdirectory mapping trick. Actually, the member who posted that trick deserves your $5 a month for beer. Send it to Andreas F. in Berlin at the current exchange rate...

Actually, that may be the best answer -- Go ahead and have them point all of your subdomains at your Web root, then use mod_rewrite [webmasterworld.com] to sort them into subdirectories from there. Relatively easy, fully under your control, and no silly charge from your host.

Jim

BWSmith

12:59 am on Jul 24, 2004 (gmt 0)

10+ Year Member



THANKS for all your help - We are going to implement it on Monday!