How to keep URL unchanged after redirecting from one subdomain to another subdomain
I want to redirect all the queries from mobile.mydomain.net
to web.mydomain.net
, keeping the URL mobile.mydomain.net
displayed in the address bar.
The directory structure in my service provider is the following:
/root
-/vrmd
--/homepages
---/myusername
----/mydomain
-----/subdomains
------/web
-------/public
------/mobile
In my service provider configuration the address www.mydomain.net
points to /mydomain/
, the address web.mydomain.net
points to /mydomain/subdomains/web/public/
and the address mobile.mydomain.net
points to /mydomain/subdomains/mobile/
.
If I echo the value of the $_SERVER['DOCUMENT_ROOT']
constant in a simple PHP script (/mobile/index.php
), it outputs /homepages/myusername/mydomain/subdomains/mobile开发者_Go百科
.
I have some questions:
1) Where should I put the rewrite conditions and rules? In an .htaccess
file under /mydomain
or better under /mydomain/subdomains/mobile
...?
2) Which conditions and rules should I write? For example, I want mobile.mydomain.net/blog
to show only the contents of web.mydomain.net/blogs
, but not the address.
Can anyone help me?
You can't silently redirect domains like that with the Apache rewrite engine - which is probably a good thing, since this could end up as a pretty nasty security breach if someone was able to upload a malicious .htaccess to your site somehow.
You would be better off implementing a front-facing controller in your mobile site that then included the content and libraries from your main website.
精彩评论