Page is a not externally linkable
- Code, Content, and Presentation
-- Apache Web Server
---- Wildcard subdomains and a custom subdomain


lucy24 - 10:23 pm on Dec 17, 2011 (gmt 0)


Time for a chorus of

. . . but only what I tell it

It is going to m.domain.com because you haven't told it to go somewhere else. If your Redirect begins in a slash-- this applies to both mod_alias and mod_rewrite-- it will reappend the existing domain name, whatever it was. If you want it to go to a different domain name, you have to lay out the whole thing, beginning with the protocol. In fact you should get in the habit of doing this with all redirects, unless you specifically want them to stay where they were.

But you don't want a redirect, do you? You want a rewrite, so the user sees

m.example.com/blahblah

while getting content from

www.example.com/m/blahblah

That puts you into proxy territory.

Go to rewrite_rule [httpd.apache.org] and then scroll down to the table headed "all possible substitution combinations". You want the very last item in the table, right?

^/somepath(.*) http://otherhost/otherpath$1 [P] http://otherhost/otherpath/pathinfo
via internal proxy


"Internal rewrite" isn't an option. Once you've changed domain names, it's either "external redirect" or "internal proxy". So part of what you want is

RewriteCond %{THE_REQUEST} blahblah
RewriteRule ^(.*)$ http://www.example.com/m/$1 [P,QSA,L]

I'm not going to fill in the blahblah because, one, it's good for your soul to figure it out yourself, and two, I would probably get it wrong ;) But you need to look at what the user originally asked for, so you don't end up going around in circles. The [L] flag is not strictly necessary: it's implied, as with [F] and [G] (but not [R]). But it won't do any harm.


Thread source:: http://www.webmasterworld.com/apache/4398557.htm
Brought to you by WebmasterWorld: http://www.webmasterworld.com