Server-Variables in CondPattern of RewriteCond directive

Server-Variables in CondPattern of RewriteCond directive

am 22.04.2009 14:21:04 von Basil Mohamed Gohar

Hello everyone! What I am trying to do is use the server variable
%{SERVER_NAME} as the CondPattern argument to the RewriteCond
directive. However, all of my attempts appear to render the string
'%{SERVER_NAME}' as a string literal, rather than replacing it with the
variable name I expect (i.e., the value for the ServerName of the
VirtualHost).

Could someone please help me in trying to do this. I would like to use
the server variable as it would save me a lot of time as I am
configuring many different VirtualHosts with similar, but not identical,
setups, but this aspect is consistent for many of them.

Thank you all in advance!

------------------------------------------------------------ ---------
The official User-To-User support forum of the Apache HTTP Server Project.
See 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: Server-Variables in CondPattern of RewriteCond

am 22.04.2009 15:20:52 von Eric Covener

On Wed, Apr 22, 2009 at 8:21 AM, Basil Mohamed Gohar
wrote:
> Hello everyone! =A0What I am trying to do is use the server variable
> %{SERVER_NAME} as the CondPattern argument to the RewriteCond directive.
> =A0However, all of my attempts appear to render the string '%{SERVER_NAME=
}' as
> a string literal, rather than replacing it with the variable name I expec=
t
> (i.e., the value for the ServerName of the VirtualHost).
>
> Could someone please help me in trying to do this. =A0I would like to use=
the
> server variable as it would save me a lot of time as I am configuring man=
y
> different VirtualHosts with similar, but not identical, setups, but this
> aspect is consistent for many of them.

Outside of htaccess, the pattern is compiled at startup, so you can't
use variables (because they depend on parts of the request, even
ServerName).

IIUC It's feasible in per-directory, but not implemented.

--=20
Eric Covener
covener@gmail.com

------------------------------------------------------------ ---------
The official User-To-User support forum of the Apache HTTP Server Project.
See 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: Server-Variables in CondPattern of RewriteCond directive

am 22.04.2009 16:14:09 von Basil Mohamed Gohar

On 04/22/2009 09:20 PM, Eric Covener wrote:
> On Wed, Apr 22, 2009 at 8:21 AM, Basil Mohamed Gohar
> wrote:
>
>> Hello everyone! What I am trying to do is use the server variable
>> %{SERVER_NAME} as the CondPattern argument to the RewriteCond directive.
>> However, all of my attempts appear to render the string '%{SERVER_NAME}' as
>> a string literal, rather than replacing it with the variable name I expect
>> (i.e., the value for the ServerName of the VirtualHost).
>>
>> Could someone please help me in trying to do this. I would like to use the
>> server variable as it would save me a lot of time as I am configuring many
>> different VirtualHosts with similar, but not identical, setups, but this
>> aspect is consistent for many of them.
>>
>
> Outside of htaccess, the pattern is compiled at startup, so you can't
> use variables (because they depend on parts of the request, even
> ServerName).
>
> IIUC It's feasible in per-directory, but not implemented.
>
>
So, what this means is it's not possible as it stands right now, correct?

------------------------------------------------------------ ---------
The official User-To-User support forum of the Apache HTTP Server Project.
See 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: Server-Variables in CondPattern of RewriteCond

am 22.04.2009 16:17:26 von Eric Covener

On Wed, Apr 22, 2009 at 10:14 AM, Basil Mohamed Gohar
wrote:
>>
>> Outside of htaccess, the pattern is compiled at startup, so you can't
>> use variables (because they depend on parts of the request, even
>> ServerName).
>>
>> IIUC It's feasible in per-directory, but not implemented.
>>
>>
>
> So, what this means is it's not possible as it stands right now, correct?

Correct. You can usually get to the same ultimate result by putting
the variables in the 2nd argument and being more clever with captures
and multiple conditions, etc.

If you can describe what your end goal is, someone here might be able
to help construct a ruleset.

--
Eric Covener
covener@gmail.com

------------------------------------------------------------ ---------
The official User-To-User support forum of the Apache HTTP Server Project.
See 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: Server-Variables in CondPattern of RewriteCond directive

am 22.04.2009 16:30:07 von Basil Mohamed Gohar

On 04/22/2009 10:17 PM, Eric Covener wrote:
> On Wed, Apr 22, 2009 at 10:14 AM, Basil Mohamed Gohar
> wrote:
>
>>> Outside of htaccess, the pattern is compiled at startup, so you can't
>>> use variables (because they depend on parts of the request, even
>>> ServerName).
>>>
>>> IIUC It's feasible in per-directory, but not implemented.
>>>
>>>
>>>
>> So, what this means is it's not possible as it stands right now, correct?
>>
>
> Correct. You can usually get to the same ultimate result by putting
> the variables in the 2nd argument and being more clever with captures
> and multiple conditions, etc.
>
> If you can describe what your end goal is, someone here might be able
> to help construct a ruleset.
>
>
Thanks. It's quite simple, actually. What I want to do is direct all
domains that fall under a virtualhost which has many server aliases to
one canonical domain.

So, for example, if my canonical name is www.example.com, and someone
accesses example.com or example.net (all of which are aliases in
VirtualHost block), I want a redirect to be issued pointing to the
canonical ServerName value (www.example.com). Since this is already
stored in %{SERVER_NAME}, I thought it would be best to use it, because
I have this kind of behavior on many, but not all, VirtualHosts. It
would save me a lot of time.

------------------------------------------------------------ ---------
The official User-To-User support forum of the Apache HTTP Server Project.
See 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: Server-Variables in CondPattern of RewriteCond

am 22.04.2009 17:11:30 von Tom Evans

On Wed, 2009-04-22 at 22:30 +0800, Basil Mohamed Gohar wrote:
> On 04/22/2009 10:17 PM, Eric Covener wrote:
> > On Wed, Apr 22, 2009 at 10:14 AM, Basil Mohamed Gohar
> > wrote:
> >
> >>> Outside of htaccess, the pattern is compiled at startup, so you can't
> >>> use variables (because they depend on parts of the request, even
> >>> ServerName).
> >>>
> >>> IIUC It's feasible in per-directory, but not implemented.
> >>>
> >>>
> >>>
> >> So, what this means is it's not possible as it stands right now, correct?
> >>
> >
> > Correct. You can usually get to the same ultimate result by putting
> > the variables in the 2nd argument and being more clever with captures
> > and multiple conditions, etc.
> >
> > If you can describe what your end goal is, someone here might be able
> > to help construct a ruleset.
> >
> >
> Thanks. It's quite simple, actually. What I want to do is direct all
> domains that fall under a virtualhost which has many server aliases to
> one canonical domain.
>
> So, for example, if my canonical name is www.example.com, and someone
> accesses example.com or example.net (all of which are aliases in
> VirtualHost block), I want a redirect to be issued pointing to the
> canonical ServerName value (www.example.com). Since this is already
> stored in %{SERVER_NAME}, I thought it would be best to use it, because
> I have this kind of behavior on many, but not all, VirtualHosts. It
> would save me a lot of time.
>

RewriteCond %{HTTP_HOST} !^(www.foo.com)$
RewriteRule ^/(.*) http://www.foo.com/$1 [R=301,L]

This is an FAQ iirc?

http://httpd.apache.org/docs/2.2/rewrite/rewrite_guide.html# canonicalhost

HTH

Tom



------------------------------------------------------------ ---------
The official User-To-User support forum of the Apache HTTP Server Project.
See 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: Server-Variables in CondPattern of RewriteConddirective

am 22.04.2009 17:22:54 von Basil Mohamed Gohar

On 04/22/2009 11:11 PM, Tom Evans wrote:
> On Wed, 2009-04-22 at 22:30 +0800, Basil Mohamed Gohar wrote:
>
>> On 04/22/2009 10:17 PM, Eric Covener wrote:
>>
>>> On Wed, Apr 22, 2009 at 10:14 AM, Basil Mohamed Gohar
>>> wrote:
>>>
>>>
>>>>> Outside of htaccess, the pattern is compiled at startup, so you can't
>>>>> use variables (because they depend on parts of the request, even
>>>>> ServerName).
>>>>>
>>>>> IIUC It's feasible in per-directory, but not implemented.
>>>>>
>>>>>
>>>>>
>>>>>
>>>> So, what this means is it's not possible as it stands right now, correct?
>>>>
>>>>
>>> Correct. You can usually get to the same ultimate result by putting
>>> the variables in the 2nd argument and being more clever with captures
>>> and multiple conditions, etc.
>>>
>>> If you can describe what your end goal is, someone here might be able
>>> to help construct a ruleset.
>>>
>>>
>>>
>> Thanks. It's quite simple, actually. What I want to do is direct all
>> domains that fall under a virtualhost which has many server aliases to
>> one canonical domain.
>>
>> So, for example, if my canonical name is www.example.com, and someone
>> accesses example.com or example.net (all of which are aliases in
>> VirtualHost block), I want a redirect to be issued pointing to the
>> canonical ServerName value (www.example.com). Since this is already
>> stored in %{SERVER_NAME}, I thought it would be best to use it, because
>> I have this kind of behavior on many, but not all, VirtualHosts. It
>> would save me a lot of time.
>>
>>
>
> RewriteCond %{HTTP_HOST} !^(www.foo.com)$
> RewriteRule ^/(.*) http://www.foo.com/$1 [R=301,L]
>
> This is an FAQ iirc?
>
> http://httpd.apache.org/docs/2.2/rewrite/rewrite_guide.html# canonicalhost
>
> HTH
>
> Tom
>
Writing it by hand for all the different VirtualHosts is what I was
trying to avoid. Doing it with variables was the goal, and it seems
that is not possible. I've been writing it by hand for years now. ;)

------------------------------------------------------------ ---------
The official User-To-User support forum of the Apache HTTP Server Project.
See 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: Server-Variables in CondPattern of RewriteConddirective

am 22.04.2009 17:47:45 von aw

Basil Mohamed Gohar wrote:
>>
> Writing it by hand for all the different VirtualHosts is what I was
> trying to avoid. Doing it with variables was the goal, and it seems
> that is not possible. I've been writing it by hand for years now. ;)
>
I think for this kind of stuff, you should have a look at mod_perl.
Not necessarily for the faint-hearted, but you definitely /can/ do this
with it.
http://perl.apache.org
user's list : modperl@perl.apache.org



------------------------------------------------------------ ---------
The official User-To-User support forum of the Apache HTTP Server Project.
See 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: Server-Variables in CondPattern of RewriteConddirective

am 22.04.2009 17:52:25 von Basil Mohamed Gohar

On 04/22/2009 11:47 PM, André Warnier wrote:
> Basil Mohamed Gohar wrote:
>> Writing it by hand for all the different VirtualHosts is what I was
>> trying to avoid. Doing it with variables was the goal, and it seems
>> that is not possible. I've been writing it by hand for years now. ;)
>>
> I think for this kind of stuff, you should have a look at mod_perl.
> Not necessarily for the faint-hearted, but you definitely /can/ do
> this with it.
> http://perl.apache.org
> user's list : modperl@perl.apache.org
Thanks for the suggestion. I think I'll keep Perl out of this. I'll
just hard code each VirtualHost's canonical name in the rewrite
conditions & rules.

------------------------------------------------------------ ---------
The official User-To-User support forum of the Apache HTTP Server Project.
See 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: Server-Variables in CondPattern of RewriteCond

am 22.04.2009 18:48:03 von Tom Evans

On Wed, 2009-04-22 at 23:22 +0800, Basil Mohamed Gohar wrote:
> On 04/22/2009 11:11 PM, Tom Evans wrote:
> > On Wed, 2009-04-22 at 22:30 +0800, Basil Mohamed Gohar wrote:
> >
> >> On 04/22/2009 10:17 PM, Eric Covener wrote:
> >>
> >>> On Wed, Apr 22, 2009 at 10:14 AM, Basil Mohamed Gohar
> >>> wrote:
> >>>
> >>>
> >>>>> Outside of htaccess, the pattern is compiled at startup, so you can't
> >>>>> use variables (because they depend on parts of the request, even
> >>>>> ServerName).
> >>>>>
> >>>>> IIUC It's feasible in per-directory, but not implemented.
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>> So, what this means is it's not possible as it stands right now, correct?
> >>>>
> >>>>
> >>> Correct. You can usually get to the same ultimate result by putting
> >>> the variables in the 2nd argument and being more clever with captures
> >>> and multiple conditions, etc.
> >>>
> >>> If you can describe what your end goal is, someone here might be able
> >>> to help construct a ruleset.
> >>>
> >>>
> >>>
> >> Thanks. It's quite simple, actually. What I want to do is direct all
> >> domains that fall under a virtualhost which has many server aliases to
> >> one canonical domain.
> >>
> >> So, for example, if my canonical name is www.example.com, and someone
> >> accesses example.com or example.net (all of which are aliases in
> >> VirtualHost block), I want a redirect to be issued pointing to the
> >> canonical ServerName value (www.example.com). Since this is already
> >> stored in %{SERVER_NAME}, I thought it would be best to use it, because
> >> I have this kind of behavior on many, but not all, VirtualHosts. It
> >> would save me a lot of time.
> >>
> >>
> >
> > RewriteCond %{HTTP_HOST} !^(www.foo.com)$
> > RewriteRule ^/(.*) http://www.foo.com/$1 [R=301,L]
> >
> > This is an FAQ iirc?
> >
> > http://httpd.apache.org/docs/2.2/rewrite/rewrite_guide.html# canonicalhost
> >
> > HTH
> >
> > Tom
> >
> Writing it by hand for all the different VirtualHosts is what I was
> trying to avoid. Doing it with variables was the goal, and it seems
> that is not possible. I've been writing it by hand for years now. ;)

Ah yes, that is different. I actually wrote a module to manage this for
my servers (the canonical rewrite rule doesn't work in certain edge
cases), it doesn't detect it automatically based upon the vhosts
ServerName (it uses a directive), but that should certainly be possible.
Let me have a look this evening...

Cheers

Tom


------------------------------------------------------------ ---------
The official User-To-User support forum of the Apache HTTP Server Project.
See 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: Server-Variables in CondPattern of RewriteCond

am 22.04.2009 19:02:21 von Eric Covener

On Wed, Apr 22, 2009 at 12:48 PM, Tom Evans wrote:
> Ah yes, that is different. I actually wrote a module to manage this for
> my servers (the canonical rewrite rule doesn't work in certain edge
> cases), it doesn't detect it automatically based upon the vhosts
> ServerName (it uses a directive), but that should certainly be possible.
> Let me have a look this evening...
>
> Cheers
>
> Tom
>

I am wondering if something like this is close (not even desk-checked)

UseCanonicalname on
RewriteCond %{HTTP_HOST} (.+)
RewriteCond %{SERVER_NAME} !=%1
RewriteRule .* http://%{SERVER_NAME}$1 [R]

or comedy single-condition option:

RewriteCond %{HTTP_HOST},%{SERVER_NAME} !(.+),\1
RewriteRule .* http://%{SERVER_NAME}$1 [R]

--
Eric Covener
covener@gmail.com

------------------------------------------------------------ ---------
The official User-To-User support forum of the Apache HTTP Server Project.
See 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: Server-Variables in CondPattern of RewriteCond

am 22.04.2009 19:06:08 von Eric Covener

On Wed, Apr 22, 2009 at 1:02 PM, Eric Covener wrote:
> RewriteRule .* http://%{SERVER_NAME}$1 [R]
> RewriteRule .* http://%{SERVER_NAME}$1 [R]

I'll head Andre off -- yes you need to actually capture something to use $1

--
Eric Covener
covener@gmail.com

------------------------------------------------------------ ---------
The official User-To-User support forum of the Apache HTTP Server Project.
See 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: Server-Variables in CondPattern of RewriteCond directive

am 22.04.2009 20:37:29 von aw

Eric Covener wrote:
> On Wed, Apr 22, 2009 at 1:02 PM, Eric Covener wrote:
>> RewriteRule .* http://%{SERVER_NAME}$1 [R]
>> RewriteRule .* http://%{SERVER_NAME}$1 [R]
>
> I'll head Andre off -- yes you need to actually capture something to use $1
>
;-)
Well actually, I had pretty much accepted the negative verdict of the
Apache and mod_rewrite gurus, and the (understandable) objection of the
OP to plugin mod_perl just for that, and was think more of something
done outside of Apache (still using perl mind you), like so :

- assuming the OP is running this Apache on some nix-like box
- assuming the OP's VHost configurations are in separate conf files
located in some directory like /etc/apache2/hosts.d/*.conf, and being
included in the main httpd.conf at Apache (re)start
- assuming one could create some text file containing the canonical
hostnames and their corresponding less-desirable aliases
- one could then create another subdirectory of /etc/apache2/ such as
/etc/apache2/hosts-templates.d/ and place a prototype version of the
vhost config files there
- then by some judicious use of a (perl) script running just prior to
apachectl in /etc/init.d/apache2, one could pre-process the templates
into /etc/hosts.d/*.conf, replacing/inserting the appropriate rules
where they need to go.
- which would have the advantage of making this static as far as Apache
is concerned and avoid many run-time per-request cpu-consuming evaluations







------------------------------------------------------------ ---------
The official User-To-User support forum of the Apache HTTP Server Project.
See 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: Server-Variables in CondPattern of RewriteConddirective

am 22.04.2009 21:22:47 von Tom Evans

On Wed, 2009-04-22 at 23:22 +0800, Basil Mohamed Gohar wrote:
> On 04/22/2009 11:11 PM, Tom Evans wrote:
> > On Wed, 2009-04-22 at 22:30 +0800, Basil Mohamed Gohar wrote:
> >
> >> On 04/22/2009 10:17 PM, Eric Covener wrote:
> >>
> >>> On Wed, Apr 22, 2009 at 10:14 AM, Basil Mohamed Gohar
> >>> wrote:
> >>>
> >>>
> >>>>> Outside of htaccess, the pattern is compiled at startup, so you can't
> >>>>> use variables (because they depend on parts of the request, even
> >>>>> ServerName).
> >>>>>
> >>>>> IIUC It's feasible in per-directory, but not implemented.
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>> So, what this means is it's not possible as it stands right now, correct?
> >>>>
> >>>>
> >>> Correct. You can usually get to the same ultimate result by putting
> >>> the variables in the 2nd argument and being more clever with captures
> >>> and multiple conditions, etc.
> >>>
> >>> If you can describe what your end goal is, someone here might be able
> >>> to help construct a ruleset.
> >>>
> >>>
> >>>
> >> Thanks. It's quite simple, actually. What I want to do is direct all
> >> domains that fall under a virtualhost which has many server aliases to
> >> one canonical domain.
> >>
> >> So, for example, if my canonical name is www.example.com, and someone
> >> accesses example.com or example.net (all of which are aliases in
> >> VirtualHost block), I want a redirect to be issued pointing to the
> >> canonical ServerName value (www.example.com). Since this is already
> >> stored in %{SERVER_NAME}, I thought it would be best to use it, because
> >> I have this kind of behavior on many, but not all, VirtualHosts. It
> >> would save me a lot of time.
> >>
> >>
> >
> > RewriteCond %{HTTP_HOST} !^(www.foo.com)$
> > RewriteRule ^/(.*) http://www.foo.com/$1 [R=301,L]
> >
> > This is an FAQ iirc?
> >
> > http://httpd.apache.org/docs/2.2/rewrite/rewrite_guide.html# canonicalhost
> >
> > HTH
> >
> > Tom
> >
> Writing it by hand for all the different VirtualHosts is what I was
> trying to avoid. Doing it with variables was the goal, and it seems
> that is not possible. I've been writing it by hand for years now. ;)
>

So, I pulled out the canonicalization module I had, it didn't quite do
it how you initially wanted (you had to specify the host name you wanted
to be canonical), I can see the benefit of having it that way. Also, it
was only 8 lines to add :)

http://svn.nubtek.com/svn/public/mod_server_name_c14n/mod_se rver_name_c14n.c

Have a read of it, it really is a simple module. This is the vhost I use
for testing it:


ServerName canon
ServerAlias notcanon also-not-canon
DocumentRoot /var/empty

Order allow,deny
Allow from all


ServerNameIsCanonical On
#SetCanonicalServerName canon


It is an extra module to add, but its just a tiny one :) Assuming your
apache installation is correct, just download the .c file to a folder
somewhere and run
apxs -c mod_server_name_c14n.c
sudo apxs -i -a mod_server_name_c14n.c

``apxs -c`` compiles the module, ``apxs -i -a`` installs it to your
apache modules folder, and activates it (adds the LoadModule line) in
your httpd.conf

Cheers

Tom


------------------------------------------------------------ ---------
The official User-To-User support forum of the Apache HTTP Server Project.
See 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: Server-Variables in CondPattern of RewriteConddirective

am 23.04.2009 15:59:25 von Basil Mohamed Gohar

On 04/23/2009 03:22 AM, Tom Evans wrote:
> On Wed, 2009-04-22 at 23:22 +0800, Basil Mohamed Gohar wrote:
>
>> On 04/22/2009 11:11 PM, Tom Evans wrote:
>>
>>> On Wed, 2009-04-22 at 22:30 +0800, Basil Mohamed Gohar wrote:
>>>
>>>
>>>> On 04/22/2009 10:17 PM, Eric Covener wrote:
>>>>
>>>>
>>>>> On Wed, Apr 22, 2009 at 10:14 AM, Basil Mohamed Gohar
>>>>> wrote:
>>>>>
>>>>>
>>>>>
>>>>>>> Outside of htaccess, the pattern is compiled at startup, so you can't
>>>>>>> use variables (because they depend on parts of the request, even
>>>>>>> ServerName).
>>>>>>>
>>>>>>> IIUC It's feasible in per-directory, but not implemented.
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>> So, what this means is it's not possible as it stands right now, correct?
>>>>>>
>>>>>>
>>>>>>
>>>>> Correct. You can usually get to the same ultimate result by putting
>>>>> the variables in the 2nd argument and being more clever with captures
>>>>> and multiple conditions, etc.
>>>>>
>>>>> If you can describe what your end goal is, someone here might be able
>>>>> to help construct a ruleset.
>>>>>
>>>>>
>>>>>
>>>>>
>>>> Thanks. It's quite simple, actually. What I want to do is direct all
>>>> domains that fall under a virtualhost which has many server aliases to
>>>> one canonical domain.
>>>>
>>>> So, for example, if my canonical name is www.example.com, and someone
>>>> accesses example.com or example.net (all of which are aliases in
>>>> VirtualHost block), I want a redirect to be issued pointing to the
>>>> canonical ServerName value (www.example.com). Since this is already
>>>> stored in %{SERVER_NAME}, I thought it would be best to use it, because
>>>> I have this kind of behavior on many, but not all, VirtualHosts. It
>>>> would save me a lot of time.
>>>>
>>>>
>>>>
>>> RewriteCond %{HTTP_HOST} !^(www.foo.com)$
>>> RewriteRule ^/(.*) http://www.foo.com/$1 [R=301,L]
>>>
>>> This is an FAQ iirc?
>>>
>>> http://httpd.apache.org/docs/2.2/rewrite/rewrite_guide.html# canonicalhost
>>>
>>> HTH
>>>
>>> Tom
>>>
>>>
>> Writing it by hand for all the different VirtualHosts is what I was
>> trying to avoid. Doing it with variables was the goal, and it seems
>> that is not possible. I've been writing it by hand for years now. ;)
>>
>>
>
> So, I pulled out the canonicalization module I had, it didn't quite do
> it how you initially wanted (you had to specify the host name you wanted
> to be canonical), I can see the benefit of having it that way. Also, it
> was only 8 lines to add :)
>
> http://svn.nubtek.com/svn/public/mod_server_name_c14n/mod_se rver_name_c14n.c
>
> Have a read of it, it really is a simple module. This is the vhost I use
> for testing it:
>
>
> ServerName canon
> ServerAlias notcanon also-not-canon
> DocumentRoot /var/empty
>
> Order allow,deny
> Allow from all
>

>
> ServerNameIsCanonical On
> #SetCanonicalServerName canon
>

>
> It is an extra module to add, but its just a tiny one :) Assuming your
> apache installation is correct, just download the .c file to a folder
> somewhere and run
> apxs -c mod_server_name_c14n.c
> sudo apxs -i -a mod_server_name_c14n.c
>
> ``apxs -c`` compiles the module, ``apxs -i -a`` installs it to your
> apache modules folder, and activates it (adds the LoadModule line) in
> your httpd.conf
>
> Cheers
>
> Tom
Thank you, Tom, for taking the time out to help with this and share your
solution with me. I'm not sure, though, I'm going to be able to use it
immediately. I've decided, therefore, to just suck it up and write out
the domain names directly. I hope your module will find its way into
the official httpd release, though.

------------------------------------------------------------ ---------
The official User-To-User support forum of the Apache HTTP Server Project.
See 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