You are here: Re: rewrite for sub-domains... « All PHP « IT news, forums, messages
Re: rewrite for sub-domains...

Posted by Kentor on 12/07/06 15:11

RewriteCond %{HTTP_HOST} !^www <- this is for not catching some
subdomains?
#(Or any other subdomains you don't want to catch)
RewriteRule ^(.*)$ searchForm.php?location=%1&foo=$1 [L,QSA]

and whats 'foo' for? this is for another variable which i dont need i
guess right?

Rik wrote:
> 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

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация