deem
deem

Reputation: 1884

Subdomain forward to another subdomain without redirecting

I've spent an amout of time to try solve it, and finally without any effects.

I have a casual subdomain like test.example.com and a mobile subdomain m.test.example.com. Every subdomain has own directory test (I have my scripts here) and m.test. I need to forward users from m.test.example.com to test.example.com without redirecting to test.example.com.

I know it easy to do it by Virtual Hosts or cpanel, but I need to do it on shared hosting with DirectAdmin (user level only). I think about mod_rewrite, and I also tried PHP symlink(), but it is disabled on my hosting.

How can I forward the user from the mobile subdomain to non-mobile resources?

Upvotes: 0

Views: 98

Answers (1)

Jon Lin
Jon Lin

Reputation: 143886

Since the two domains ("test" and "m.test") have different document roots, you're going to need to reverse proxy. The problem here is mod_proxy, the proxy module, may not be loaded by your host, but you'd do something like this:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^m\.test\.example\.com$ [NC]
RewriteRule ^(.*)$ http://test.example.com/$1 [L,P]

These rules would be in the /m.test/ folder, the document root of the m.test.example.com subdomain. The P flag tells mod_rewrite to hand the request to mod_proxy to reverse proxy instead of redirecting the browser.

Upvotes: 1

Related Questions