|
Posted by Rik on 12/07/06 00:32
Christoph Burschka wrote:
> Kentor schrieb:
>> Hello, I know how to use rewrite on my main domain page but when it
>> comes to sub-domains it just doesn't work. I'm trying to have the
>> url: http://montreal.mysite.com show the page that is shown by
>> www.mysite.com/searchForm.php?location=Montreal and another
>> subdomain like http://www.toronto.mysite.com show the page for
>> www.mysite.com/searchForm.php?location=Toronto
>> thanks for your help.
>>
> mod_rewrite doesn't work across sub-domains, as far as I know - at
> least not unless you use the [R] flag which redirects the user to the
> URL you specify.
>
> But that means the user will actually receive a redirect response and
> will see the new URL in their address bar - if you are using
> mod_rewrite for clean URLs, this probably isn't what you want.
>
>
> <?php
> if
> (preg_match('/^(.*)\.mysite.com$/',$_SERVER['HTTP_HOST'],$match)
> { if ($match[1]!='www') $_GET['location']=$match[1]; }
>>
>
> This will check whether the page was called with *.mysite.com and, if
> it was, move the subdomain over to the location parameter.
>
> The search form will then work as if it had been called with
> searchForm.php?location=*.
>
> Note that this will only work if the subdomains are all served from
> the same folder on the server; that is, if it would also be possible
> to visit this URL:
>
> http://toronto.mysite.com/searchForm.php
>
> If it doesn't, you need to change that - or at least copy the search
> form over to the other folder.
Yup, to clarify:
It is possible to have a default subdomain:
- you have to have a DNS record *.example.com IN A {ip}
- your webserver has to have this configured (using in Apache: ServerAlias
*.example.com)
Then you can use mod_rewrite in your wildcard domain:
RewriteCond %{HTTP_HOST} ^([^.]+\).example.com
RewriteCond %{HTTP_HOST} !^www
#(Or any other subdomains you don't want to catch)
RewriteRule ^(.*)$ searchForm.php?location=%1&foo=$1 [L,QSA]
--
Rik Wasmus
[Back to original message]
|