You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Dmitry Hazin <dh...@gmail.com> on 2007/04/30 19:47:14 UTC

[users@httpd] ServerAlias and redirecting, please help

Hi there,

I searched for a while but couldn't point out what is the right way to
do the following:

We have the following virtualhost configuration:

...
ServerName www.site.ru
	DocumentRoot /home/www/ru.site.www
	ServerAlias xx.site.com
...

What I need is to redirect from http://xx.site.com to the
http://www.site.ru/some/location

I tried RedirectPermanent but it seems to work only for locations
relative to the virtualhost root.
RewriteRule also had no effect.

What is the correct way to configure apache so it will redirect from
xx.site.com to http://www.site.ru/some/location ?

Any help greatly appreciated!
Thanks in advance,
Dmitry

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] ServerAlias and redirecting, please help

Posted by Dmitry Hazin <dh...@gmail.com>.
Ok, I tried your method and it worked fine for me! I don't think that
I need to spend much time debugging rewriterules so I will stay with
it.
Thanks in advance!

2007/5/2, Joshua Slive <jo...@slive.ca>:
> On 5/2/07, Dmitry Hazin <dh...@gmail.com> wrote:
> > Yes, that was my mistake. Anyway, without that line it didn't work too :(
> > It seems that apache doesn't read RewriteRule directive after it had
> > read ServerAlias one..
>
> No, that's not true. As I said, if you want to debug mod_rewite you
> need to use the RewriteLog. It could also simply be a question of not
> putting the directives in the right place. They should be placed
> inside the <VirtualHost> where you want them to have an effect.
>
> > What do you mean "the technique of having two <VirtualHost>s"?
> > We do have 2 virtualhosts: one for www.site.com and one for www.site.ru
> > Do you suppose putting redirect directive into the www.site.com one or what?
> > And what to do with ServerAlias then?
>
> I mean that at this reference
> http://wiki.apache.org/httpd/Recipes/CanonicalHostNames
> there are two techniques for canonicalizing urls. You chose to use the
> second one rather than the first one, which I find simpler.
>
> To use <VirtualHost>s, you simply setup a separate <VirtualHost>
> section (with appropriate ServerName) for each hostname that you wish
> to treat differently. The VirtualHost for xx.site.com would contain
> nothing other than a ServerName and a Redirect pointing to the
> appropriate location on www.site.ru.
>
> ---------------------------------------------------------------------
> The official User-To-User support forum of the Apache HTTP Server Project.
> See <URL:http://httpd.apache.org/userslist.html> for more info.
> To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
>    "   from the digest: users-digest-unsubscribe@httpd.apache.org
> For additional commands, e-mail: users-help@httpd.apache.org
>
>

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] ServerAlias and redirecting, please help

Posted by Joshua Slive <jo...@slive.ca>.
On 5/2/07, Dmitry Hazin <dh...@gmail.com> wrote:
> Yes, that was my mistake. Anyway, without that line it didn't work too :(
> It seems that apache doesn't read RewriteRule directive after it had
> read ServerAlias one..

No, that's not true. As I said, if you want to debug mod_rewite you
need to use the RewriteLog. It could also simply be a question of not
putting the directives in the right place. They should be placed
inside the <VirtualHost> where you want them to have an effect.

> What do you mean "the technique of having two <VirtualHost>s"?
> We do have 2 virtualhosts: one for www.site.com and one for www.site.ru
> Do you suppose putting redirect directive into the www.site.com one or what?
> And what to do with ServerAlias then?

I mean that at this reference
http://wiki.apache.org/httpd/Recipes/CanonicalHostNames
there are two techniques for canonicalizing urls. You chose to use the
second one rather than the first one, which I find simpler.

To use <VirtualHost>s, you simply setup a separate <VirtualHost>
section (with appropriate ServerName) for each hostname that you wish
to treat differently. The VirtualHost for xx.site.com would contain
nothing other than a ServerName and a Redirect pointing to the
appropriate location on www.site.ru.

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] ServerAlias and redirecting, please help

Posted by Dmitry Hazin <dh...@gmail.com>.
Yes, that was my mistake. Anyway, without that line it didn't work too :(
It seems that apache doesn't read RewriteRule directive after it had
read ServerAlias one..
What do you mean "the technique of having two <VirtualHost>s"?
We do have 2 virtualhosts: one for www.site.com and one for www.site.ru
Do you suppose putting redirect directive into the www.site.com one or what?
And what to do with ServerAlias then?

2007/5/2, Joshua Slive <jo...@slive.ca>:
> On 5/2/07, Dmitry Hazin <dh...@gmail.com> wrote:
> > I tried the following directives to force redirect:
> >
>
> Well, I think the technique of having two <VirtualHost>s is clearer,
> but anyway...
>
> > RewriteCond %{HTTP_HOST}   ^xx\.site\.com [NC]
> > RewriteCond %{HTTP_HOST}   ^$
> > RewriteRule ^/(.*)         http://www.site.ru/some/location/$1 [L,R=301]
>
> Delete the second RewriteCond. Those conditions must all be met for
> the RewriteRule to be applied, and obviously the Host can't be
> simultaneously xx.site.com and empty.
>
> Also, use the RewriteLog to debug problems with mod_rewrite.
>
> Joshua.
>
> ---------------------------------------------------------------------
> The official User-To-User support forum of the Apache HTTP Server Project.
> See <URL:http://httpd.apache.org/userslist.html> for more info.
> To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
>    "   from the digest: users-digest-unsubscribe@httpd.apache.org
> For additional commands, e-mail: users-help@httpd.apache.org
>
>

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] ServerAlias and redirecting, please help

Posted by Joshua Slive <jo...@slive.ca>.
On 5/2/07, Dmitry Hazin <dh...@gmail.com> wrote:
> I tried the following directives to force redirect:
>

Well, I think the technique of having two <VirtualHost>s is clearer,
but anyway...

> RewriteCond %{HTTP_HOST}   ^xx\.site\.com [NC]
> RewriteCond %{HTTP_HOST}   ^$
> RewriteRule ^/(.*)         http://www.site.ru/some/location/$1 [L,R=301]

Delete the second RewriteCond. Those conditions must all be met for
the RewriteRule to be applied, and obviously the Host can't be
simultaneously xx.site.com and empty.

Also, use the RewriteLog to debug problems with mod_rewrite.

Joshua.

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] ServerAlias and redirecting, please help

Posted by Dmitry Hazin <dh...@gmail.com>.
I tried the following directives to force redirect:

RewriteCond %{HTTP_HOST}   ^xx\.site\.com [NC]
RewriteCond %{HTTP_HOST}   ^$
RewriteRule ^/(.*)         http://www.site.ru/some/location/$1 [L,R=301]

But still no success; it opens the index page of the
http://www.site.ru when typing 'xx.site.com' but url doesn't change in
the browser and index page is opened instead of
http://www.site.ru/some/location

It seems that ServerAlias directive overrides RewriteRule one, because
the server response to xx.site.com is 302 Moved Temporarily instead of
supposed 301 written in the RewriteRule. Does this mean that I need to
remove xx.site.com from ServerAlias directive and if so what will be
the correct configuration?

Thanks,
Dmitry

2007/5/1, Joshua Slive <jo...@slive.ca>:
> On 4/30/07, Dmitry Hazin <dh...@gmail.com> wrote:
>
> > What is the correct way to configure apache so it will redirect from
> > xx.site.com to http://www.site.ru/some/location ?
>
> See:
> http://wiki.apache.org/httpd/Recipes/CanonicalHostNames
>
> Joshua.
>
> ---------------------------------------------------------------------
> The official User-To-User support forum of the Apache HTTP Server Project.
> See <URL:http://httpd.apache.org/userslist.html> for more info.
> To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
>    "   from the digest: users-digest-unsubscribe@httpd.apache.org
> For additional commands, e-mail: users-help@httpd.apache.org
>
>

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] ServerAlias and redirecting, please help

Posted by Joshua Slive <jo...@slive.ca>.
On 4/30/07, Dmitry Hazin <dh...@gmail.com> wrote:

> What is the correct way to configure apache so it will redirect from
> xx.site.com to http://www.site.ru/some/location ?

See:
http://wiki.apache.org/httpd/Recipes/CanonicalHostNames

Joshua.

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org