Rewrite Voodoo pt. 2

Rewrite Voodoo pt. 2

am 19.01.2010 15:47:00 von Reese

Hi everyone,

We're experiencing some difficulty that I'm not entirely sure of
the origin of. Most URLs to content in a subdomain link through
the subdomain, but a few are linking a subdirectory of the main
domain instead

domain.ext/subdirectory/content.ext (the few)
subdomain.ext/content.ext (the many and preferred)

So I wrote the below for inclusion in the main domain .htaccess
file, it's off the top of my head so I'm wondering if anyone sees
anything wrong with it and if yes, how it would be fixed (watch
for line wrap):

RewriteEngine On
RewriteRule ^(www\.)?domain\.ext/subdomain/(.*)$
subdomain\.domain\.ext/$2 [R=301,L]


Reese




------------------------------------------------------------ ---------
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: Rewrite Voodoo pt. 2

am 19.01.2010 16:33:11 von Tom Evans

On Tue, Jan 19, 2010 at 2:47 PM, Reese wrote:
> Hi everyone,
>
> We're experiencing some difficulty that I'm not entirely sure of
> the origin of. Most URLs to content in a subdomain link through
> the subdomain, but a few are linking a subdirectory of the main
> domain instead
>
> domain.ext/subdirectory/content.ext (the few)
> subdomain.ext/content.ext (the many and preferred)
>
> So I wrote the below for inclusion in the main domain .htaccess
> file, it's off the top of my head so I'm wondering if anyone sees
> anything wrong with it and if yes, how it would be fixed (watch
> for line wrap):
>
> RewriteEngine On
> RewriteRule  ^(www\.)?domain\.ext/subdomain/(.*)$ subdomain\.domain\=
..ext/$2
> [R=3D301,L]
>
>
> Reese
>
>

RewriteRules operate over the part of the URL after the host and
before the query string, so you would be wanting to try out
RewriteCond.

See http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html#rewrit erule
, in particular the section labelled 'What is matched'.

Cheers

Tom

PS:

Rewrite rule problems generally get solved quicker if you try and
write them yourself, turn on the RewriteLog and test them against some
sample URLs. If it doesn't work, providing that information to the
list will get you more/faster/more accurate responses.

------------------------------------------------------------ ---------
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: Rewrite Voodoo pt. 2

am 19.01.2010 20:22:03 von Reese

I suggested this:

>> RewriteEngine On
>> RewriteRule ^(www\.)?domain\.ext/subdomain/(.*)$ subdomain\.domain\.ext/$2
>> [R=301,L]

On 19-Jan-10 10:33, Tom Evans wrote:

> RewriteRules operate over the part of the URL after the host and
> before the query string, so you would be wanting to try out
> RewriteCond.

Totally opaque answer.

> See http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html#rewrit erule
> , in particular the section labelled 'What is matched'.



> Cheers
>
> Tom
>
> PS:
>
> Rewrite rule problems generally get solved quicker if you try and
> write them yourself, turn on the RewriteLog and test them against some
> sample URLs. If it doesn't work, providing that information to the
> list will get you more/faster/more accurate responses.
>
> ------------------------------------------------------------ ---------
> 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
>
>



------------------------------------------------------------ ---------
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: Rewrite Voodoo pt. 2

am 19.01.2010 20:32:51 von Reese

It looks like that one escaped before I was finished replying.

My apologies.


I suggested this:

>> RewriteEngine On
>> RewriteRule ^(www\.)?domain\.ext/subdomain/(.*)$ subdomain\.domain\.ext/$2
>> [R=301,L]

On 19-Jan-10 10:33, Tom Evans wrote:

> RewriteRules operate over the part of the URL after the host and
> before the query string, so you would be wanting to try out
> RewriteCond.

Okay, The issue is, links to domain.ext/subdirectoryX/ versus
to the matching sub(.*)X.domain.ext - if that makes more sense
to you.

> See http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html#rewrit erule
> , in particular the section labelled 'What is matched'.

Seen it.

In case you were unclear because you weren't here earlier: I'm not
very good with opaque instructions like, read the incomprehensible
manual. Mod_rewrite is voodoo. Cool voodoo, but still voodoo and
no amount of RTFM will suffice when the manual is incomplete.

Help me understand why my suggestion above does not work, I'll
learn from that. I can throw URLs at you, too.

Reese


------------------------------------------------------------ ---------
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: Rewrite Voodoo pt. 2

am 19.01.2010 20:57:53 von Eric Covener

On 1/19/10, Reese wrote:
> > > RewriteRule ^(www\.)?domain\.ext/subdomain/(.*)$ subdomain\.domain\.ext/$2

> > RewriteRules operate over the part of the URL after the host and
> > before the query string, so you would be wanting to try out
> > RewriteCond.
> >
>
> > See
> http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html#rewrit erule
> > , in particular the section labelled 'What is matched'.
> >
>
> Seen it.
>
> In case you were unclear because you weren't here earlier: I'm not
> very good with opaque instructions like, read the incomprehensible
> manual. Mod_rewrite is voodoo. Cool voodoo, but still voodoo and
> no amount of RTFM will suffice when the manual is incomplete.

Tom pointed you to the FAQ that makes your rule appear to be a no-op
and even took the time to restate it in-line. Over and above the call
of duty, IMO.

> Help me understand why my suggestion above does not work, I'll
> learn from that. I can throw URLs at you, too.

Does interpretive dance meet your individualized educational needs?

--
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: Rewrite Voodoo pt. 2

am 19.01.2010 21:19:08 von Reese

On 19-Jan-10 14:57, Eric Covener wrote:

> Tom pointed you to the FAQ that makes your rule appear to be a no-op
> and even took the time to restate it in-line.

What, this?

>> RewriteRules operate over the part of the URL after the host and
>> before the query string, so you would be wanting to try out
>> RewriteCond.
>>
>> See http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html#rewrit erule
>> , in particular the section labelled 'What is matched'.

It tells me that the part after the host (I want to change the host
name) and the part after the query string (that I'm not using if I
understand the usage) are tips of the iceberg. And that is the part
I'm trying to understand. And neither Tom nor you are helping.

Did I not ask how the rule might be corrected? Did I not?

> Over and above the call of duty, IMO.

Thank you for that input, Eric. Now please go over and above yourself.

>> Help me understand why my suggestion above does not work, I'll
>> learn from that. I can throw URLs at you, too.
>
> Does interpretive dance meet your individualized educational needs?

No.

Reese




------------------------------------------------------------ ---------
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: Rewrite Voodoo pt. 2

am 19.01.2010 21:23:57 von Oliver Schoenborn

Reese wrote:
>
> It tells me that the part after the host (I want to change the host
> name) and the part after the query string (that I'm not using if I
> understand the usage) are tips of the iceberg. And that is the part
> I'm trying to understand. And neither Tom nor you are helping.
>
> Did I not ask how the rule might be corrected? Did I not?
>
>> Over and above the call of duty, IMO.
>
> Thank you for that input, Eric. Now please go over and above yourself.

Well, I was going to make an attempt, but with that kind of attitude, doesn=
't feel right, regardless of how frustratring or voodoo'ish the docs are.=20

Oliver=

------------------------------------------------------------ ---------
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: Rewrite Voodoo pt. 2

am 19.01.2010 21:41:38 von Reese

On 19-Jan-10 15:23, Oliver Schoenborn wrote:

> Well, I was going to make an attempt, but with that kind of attitude, doesn't feel right, regardless of how frustratring or voodoo'ish the docs are.


My apologies to you, whether you actually make an attempt or not.
It's frustrating, when you are new at this and you get theory or
high-level text thrown at you over and over when you ask for help
at the deck-plates level. Voodoo indeed.

If you are still willing, then please help me understand the link
Tom provided and why my crude attempt at coding a solution will
not work. I've RTFM and STFW and in this place, I thought I could
find answers. not more RTFM claptrap from people who haven't walked
that mile in my shoes.

Reese


------------------------------------------------------------ ---------
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: Rewrite Voodoo pt. 2

am 19.01.2010 23:05:48 von Reese

On 19-Jan-10 10:33, Tom Evans wrote:

> RewriteRules operate over the part of the URL after the host and
> before the query string, so you would be wanting to try out
> RewriteCond.
>
> See http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html#rewrit erule
> , in particular the section labelled 'What is matched'.


"If you wish to match against the hostname, port, or query string, use a
RewriteCond with the %{HTTP_HOST}, "

I'm still not seeing it.

Could any of you be less opaque - or less of a delicate flower?

I provided my best guess and asked for help. Neither "the consequent
is a result of the precedent" nor "Read here" is of help to any
except those who qualify as BoFH operators. Please don't be one of
those, it could result in this whole list getting a bad reputation.

Reese




------------------------------------------------------------ ---------
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: Rewrite Voodoo pt. 2

am 19.01.2010 23:16:50 von pmilanese

Have to throw in something here. Tom gave you the right answers. What exactly=
is 'one of those'?

The list is comprised of good questions and answers. Not part time employees =
:)



----- Original Message -----
From: Reese [howell.r@inkworkswell.com]
Sent: 01/19/2010 05:05 PM EST
To: users@httpd.apache.org
Subject: Re: [users@httpd] Rewrite Voodoo pt. 2



On 19-Jan-10 10:33, Tom Evans wrote:

> RewriteRules operate over the part of the URL after the host and
> before the query string, so you would be wanting to try out
> RewriteCond.
>
> See http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html#rewrit erule
> , in particular the section labelled 'What is matched'.


"If you wish to match against the hostname, port, or query string, use a
RewriteCond with the %{HTTP_HOST}, "

I'm still not seeing it.

Could any of you be less opaque - or less of a delicate flower?

I provided my best guess and asked for help. Neither "the consequent
is a result of the precedent" nor "Read here" is of help to any
except those who qualify as BoFH operators. Please don't be one of
those, it could result in this whole list getting a bad reputation.

Reese




------------------------------------------------------------ ---------
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


------------------------------------------------------------ ---------
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: Rewrite Voodoo pt. 2

am 19.01.2010 23:24:20 von Reese

On 19-Jan-10 17:16, Peter J Milanese wrote:
> Have to throw in something here. Tom gave you the right answers. What
> exactly is 'one of those'?

RTFM is not always the "right" answer to the question asked.

> The list is comprised of good questions and answers. Not part time
> employees :)

My efforts are unpaid as well, you would be correct to think of this
as my foaf effort for a good cause.

My attempt was:

RewriteEngine On
RewriteRule ^(www\.)?domain\.ext/subdomain/(.*)$
subdomain\.domain\.ext/$2 [R=301,L]


I now think this would be better:

RewriteEngine On
RewriteRule ^domain\.ext/subdomain/(.*)$ subdomain\.domain\.ext/$2
[R=301,L]

but I don't know why. Or if it will work. Or why. I'd like to know why.

Reese


------------------------------------------------------------ ---------
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: Rewrite Voodoo pt. 2

am 19.01.2010 23:42:52 von pmilanese

As stated previously, RewriteRule is NOT the proper directive, and does not s=
ee the hostname.

RewriteCond will act as a filter for the hostname.

RewriteRule will not accomplish what you want, or whatever we 'think' you wan=
t. It does not know anything about hostname.

P


----- Original Message -----
From: Reese [howell.r@inkworkswell.com]
Sent: 01/19/2010 05:24 PM EST
To: users@httpd.apache.org
Subject: Re: [users@httpd] Rewrite Voodoo pt. 2



On 19-Jan-10 17:16, Peter J Milanese wrote:
> Have to throw in something here. Tom gave you the right answers. What
> exactly is 'one of those'?

RTFM is not always the "right" answer to the question asked.

> The list is comprised of good questions and answers. Not part time
> employees :)

My efforts are unpaid as well, you would be correct to think of this
as my foaf effort for a good cause.

My attempt was:

RewriteEngine On
RewriteRule ^(www\.)?domain\.ext/subdomain/(.*)$
subdomain\.domain\.ext/$2 [R=3D301,L]


I now think this would be better:

RewriteEngine On
RewriteRule ^domain\.ext/subdomain/(.*)$ subdomain\.domain\.ext/$2
[R=3D301,L]

but I don't know why. Or if it will work. Or why. I'd like to know why.

Reese


------------------------------------------------------------ ---------
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


------------------------------------------------------------ ---------
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: Rewrite Voodoo pt. 2

am 20.01.2010 00:24:06 von Jonathan Zuckerman

--0016e64b95b6506438047d8cc51b
Content-Type: text/plain; charset=UTF-8

On Tue, Jan 19, 2010 at 2:42 PM, Peter J Milanese wrote:

> As stated previously, RewriteRule is NOT the proper directive, and does not
> see the hostname.
>
> RewriteCond will act as a filter for the hostname.
> RewriteRule will not accomplish what you want, or whatever we 'think' you
> want. It does not know anything about hostname.
>
>
> P
>
>
> ----- Original Message -----
> From: Reese [howell.r@inkworkswell.com]
> Sent: 01/19/2010 05:24 PM EST
> To: users@httpd.apache.org
> Subject: Re: [users@httpd] Rewrite Voodoo pt. 2
>
>
>
> On 19-Jan-10 17:16, Peter J Milanese wrote:
>
>> Have to throw in something here. Tom gave you the right answers. What
>> exactly is 'one of those'?
>>
>
> RTFM is not always the "right" answer to the question asked.
>
> The list is comprised of good questions and answers. Not part time
>> employees :)
>>
>
> My efforts are unpaid as well, you would be correct to think of this
> as my foaf effort for a good cause.
>
> My attempt was:
>
> RewriteEngine On
> RewriteRule ^(www\.)?domain\.ext/subdomain/(.*)$ subdomain\.domain\.ext/$2
> [R=301,L]
>
>
> I now think this would be better:
>
> RewriteEngine On
> RewriteRule ^domain\.ext/subdomain/(.*)$ subdomain\.domain\.ext/$2
> [R=301,L]
>
> but I don't know why. Or if it will work. Or why. I'd like to know why.
>
> Reese
>
>
> ------------------------------------------------------------ ---------
> 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
>
>
> ------------------------------------------------------------ ---------
> 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
>
>
I'm pretty sure nobody wants this to turn into a mod_rewrite solve-it-for-me
mailing list.

--0016e64b95b6506438047d8cc51b
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

On Tue, Jan 19, 2010 at 2:42 PM, Peter J Milanes=
e <PMilanese@nyp=
l.org
>
wrote:
argin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">

As stated previously, RewriteRule is NOT the proper directive, and does not=
see the hostname.



RewriteCond will act as a filter for the hostname.

RewriteRule will not accomplish what you want, or whatever we 'think=
9; you want. It does not know anything about hostname.
>


P





----- Original Message -----

From: Reese [ >howell.r@inkworkswell.com]

Sent: 01/19/2010 05:24 PM EST

To: users@httpd=
..apache.org


Subject: Re: [users@httpd] Rewrite Voodoo pt. 2







On 19-Jan-10 17:16, Peter J Milanese wrote:

x #ccc solid;padding-left:1ex">
Have to throw in something here. Tom gave you the right answers. What exact=
ly is 'one of those'?




RTFM is not always the "right" answer to the question asked.



x #ccc solid;padding-left:1ex">
The list is comprised of good questions and answers. Not part time employee=
s :)




My efforts are unpaid as well, you would be correct to think of this

as my foaf effort for a good cause.



My attempt was:



RewriteEngine On

RewriteRule  ^(www\.)?domain\.ext/subdomain/(.*)$ subdomain\.domain\.e=
xt/$2 [R=3D301,L]





I now think this would be better:



RewriteEngine On

RewriteRule  ^domain\.ext/subdomain/(.*)$ subdomain\.domain\.ext/$2 [R=
=3D301,L]



but I don't know why. Or if it will work. Or why. I'd like to know =
why.



Reese





------------------------------------------------------------ ---------

The official User-To-User support forum of the Apache HTTP Server Project.<=
br>
See <URL: lank">http://httpd.apache.org/userslist.html> for more info.

To unsubscribe, e-mail: g" target=3D"_blank">users-unsubscribe@httpd.apache.org

 "   from the digest: cribe@httpd.apache.org" target=3D"_blank">users-digest-unsubscribe@httpd.ap=
ache.org


For additional commands, e-mail: org" target=3D"_blank">users-help@httpd.apache.org





------------------------------------------------------------ ---------

The official User-To-User support forum of the Apache HTTP Server Project.<=
br>
See <URL: lank">http://httpd.apache.org/userslist.html> for more info.

To unsubscribe, e-mail: g" target=3D"_blank">users-unsubscribe@httpd.apache.org

 "   from the digest: cribe@httpd.apache.org" target=3D"_blank">users-digest-unsubscribe@httpd.ap=
ache.org


For additional commands, e-mail: org" target=3D"_blank">users-help@httpd.apache.org




I'm pretty sure nobody wants th=
is to turn into a mod_rewrite solve-it-for-me mailing list.


--0016e64b95b6506438047d8cc51b--

Re: Rewrite Voodoo pt. 2

am 20.01.2010 00:36:15 von Eric Covener

On 1/19/10, Jonathan Zuckerman wrote:
> I'm pretty sure nobody wants this to turn into a mod_rewrite solve-it-for-me
> mailing list.

We only give out the magic incantations on IRC.

--
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: Rewrite Voodoo pt. 2

am 20.01.2010 10:40:08 von daniel.goulder

> On 19 January 2010 22:24, Reese wrote:
>
> On 19-Jan-10 17:16, Peter J Milanese wrote:
> > Have to throw in something here. Tom gave you the right answers. What
> > exactly is 'one of those'?
>
> RTFM is not always the "right" answer to the question asked.

I agree, but Tom's answer was more than simply RTFM. It was 'this is the
part of the voodoo you have misunderstood, and here is the part of the
manual which will help you to understand how this voodoo works.'

>
> My attempt was:
>
> RewriteEngine On
> RewriteRule ^(www\.)?domain\.ext/subdomain/(.*)$
> subdomain\.domain\.ext/$2 [R=301,L]
>
>
> I now think this would be better:
>
> RewriteEngine On
> RewriteRule ^domain\.ext/subdomain/(.*)$ subdomain\.domain\.ext/$2
> [R=301,L]
>

No better.

> but I don't know why. Or if it will work. Or why. I'd like to know why.

The reason why it won't work is because, as several posters (including Tom)
have already mentioned, the _RewriteRule_ will NOT be aware of the
hostname. It matches everything AFTER the hostname.

As Tom correctly stated, YOU WILL NEED A RewriteCond to match any
hostnames.

So as a first step I would respectfully suggest you add a RewriteCond
directive immediately preceding your RewriteRule, as follows:

RewriteCond %{HTTP_HOST} ^(www\.)?domain.ext$

Then carry on with your RewriteRule voodoo, taking care to note that you
CAN NOT use the domain name in a RewriteRule. Note that the HTTP_HOST
variable is available for your use on the right hand side of your
RewriteRule.

>
> Reese


____________________________________________________________ __________
This e-mail and any attached files are intended for the named addressee only. It contains information, which may be confidential and legally privileged and also protected by copyright. Unless you are the named addressee (or authorised to receive for the addressee) you may not copy or use it, or disclose it to anyone else. If you received it in error please notify the sender immediately and then delete it from your system. Please be advised that the views and opinions expressed in this e-mail may not reflect the views and opinions of Associated Newspapers Limited or any of its subsidiary companies. We make every effort to keep our network free from viruses. However, you do need to check this e-mail and any attachments to it for viruses as we can take no responsibility for any computer virus
which may be transferred by way of this e-mail. Use of this or any other e-mail facility signifies consent to any interception we might lawfully carry out to prevent abuse of these faciliti
es.
Associated Newspapers Ltd. Registered Office: Northcliffe House, 2 Derry St, Kensington, London, W8 5TT. Registered No 84121 England.

------------------------------------------------------------ ---------
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: Rewrite Voodoo pt. 2

am 20.01.2010 13:13:50 von Oliver Schoenborn

>
>> My attempt was:
>>=20
>> RewriteEngine On
>> RewriteRule ^(www\.)?domain\.ext/subdomain/(.*)$
>> subdomain\.domain\.ext/$2 [R=3D301,L]
>>=20
>> I now think this would be better:
>>=20
>> RewriteEngine On
>> RewriteRule ^domain\.ext/subdomain/(.*)$ subdomain\.domain\.ext/$2
>> [R=3D301,L]
>=20
> No better.
>=20
> ...
>=20
> As Tom correctly stated, YOU WILL NEED A RewriteCond to match any
> hostnames.
>=20
> ...
>=20
> Then carry on with your RewriteRule voodoo, taking care to note that you
> CAN NOT use the domain name in a RewriteRule. =20
>=20
You guys are very patient in answering this Reese fellow! In any case, just=
=20
one trick I have seen, to get around the "feature" you mention: include=20
a rewrite rule that modifies the URL to insert the host name. For instance,

rewriteCond $(HOST_NAME) www.domain.ext
rewriteRule ^(.*)$ $(HOST_NAME)$1
rewriteRule regexpOnPartOfHostname toWhatever

For Reese: the first rule will run only if the condition is true, and=20
will insert the domain name before the URL path. Since the first rule=20
always matches (when the condition is verified), it chains to the second
rule. In the second rule, the regexp can now contain patterns matching=20
parts of your domain.=20

So you could have=20

rewriteCond $(HOST_NAME) ^(.*)\.domain\.ext
rewriteRule ^(.*)$ $(HOST_NAME)$1
rewriteRule ^(.*)\.domain\.ext(.*) domain.ext/$1$2 [R,L]

The first rule only runs if the hostname of the query if for a subdomain,
and inserts the hostname before the path. Then the next rule finds the part
of the new URL (domain+URL) that contains subdomain name and URL path and=20
reorders them into a new domain/subdomain+path (path always starts with a
slash so no need for it).=20

Can you interpret:

rewriteCond $(HOST_NAME) ^(.*)\.domain\.ext
rewriteRule ^(.*)$ $(HOST_NAME)$1
rewriteRule ^([a-z])(.*)([0-9])\.domain\.ext(.*) www$3.domain.ext/$2_$1$4

What will it do to the following HTTP requests:

domain.ext/something
asub2.domain.ext/something
asub.domain.ext/something

Your knowledge of regexp is the only limit in how much you can chop up your=
=20
hostname to rewrite the URL.=20

Oliver=

------------------------------------------------------------ ---------
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: Rewrite Voodoo pt. 2

am 23.01.2010 14:50:44 von Reese

Apologies for the delay in responding to this, I've been busy.

On 20-Jan-10 07:13, Oliver Schoenborn wrote:

>>> RewriteEngine On
>>> RewriteRule ^domain\.ext/subdomain/(.*)$ subdomain\.domain\.ext/$2
>>> [R=301,L]
>> No better.

Dang. It's moot as far as the client is concerned, pt 1 finished my
contractual obligations for that client. Pt 2 was for my own
edification.

> You guys are very patient in answering this Reese fellow!

Well, I've been called a whole lot of things, but I think that's the
first time I've been called a fellow. I'll mark my calendar. ;)

> Can you interpret:
>
> rewriteCond $(HOST_NAME) ^(.*)\.domain\.ext

Condition, proceed for host_name matching (anySubdomain).domain.ext

> rewriteRule ^(.*)$ $(HOST_NAME)$1

Rule, I'm not sure what it does. Based on the link Tom posted, I'd
guess that it takes everything after domain.ext and appends it after
domain.ext - which would take an incoming URI request and output the
URI unchanged. But that's my guess. I don't *know* what it does for
sure. I could create a sandbox and test, but somehow that seems like
it would be cheating.

> rewriteRule ^([a-z])(.*)([0-9])\.domain\.ext(.*) www$3.domain.ext/$2_$1$4

Rule,
lowercase-alpha saved as $1
plus
zero or more of everything saved as $2
plus
0-9 numeric saved as $3
plus
domain.ext
plus
zero or more of anything saved as $4

rewrite to
www$3.domain.ext/$2_$1$4

In the case of www.domain.ext/subdomain/file220110.html this would
result in a severely fractured URL I think.

> What will it do to the following HTTP requests:

Oh wow. Here we go. For URI's that match host_name:

rewriteRule ^([a-z])(.*)([0-9])\.domain\.ext(.*) www$3.domain.ext/$2_$1$4

> domain.ext/something

www.domain.ext/something

> asub2.domain.ext/something

www.domain.ext/2_asubsomething

> asub.domain.ext/something

www.domain.ext/_asubsomething

I think.

> Your knowledge of regexp is the only limit in how much you can chop up your
> hostname to rewrite the URL.

Well, regardless of how I did, thank you. And now let's get the
nastiness over with, how did I do?

Reese


------------------------------------------------------------ ---------
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: Rewrite Voodoo pt. 2

am 23.01.2010 16:38:28 von Eric Covener

On Sat, Jan 23, 2010 at 8:50 AM, Reese wrote:
>> rewriteRule ^([a-z])(.*)([0-9])\.domain\.ext(.*) www$3.domain.ext/$2_$1$4
>
> Rule,
> lowercase-alpha saved as $1
> plus
> zero or more of everything saved as $2
> plus
> 0-9 numeric saved as $3
> plus
> domain.ext
> plus
> zero or more of anything saved as $4
>
> rewrite to
> www$3.domain.ext/$2_$1$4

What's the full input URL that you're matching?

--
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: Rewrite Voodoo pt. 2

am 23.01.2010 21:56:27 von Reese

On 23-Jan-10 10:38, Eric Covener wrote:

> What's the full input URL that you're matching?

The majority of links use string1.domain.ext/filenameDDMMYY.ext but
a minority of links use www.domain.ext/string1/filenameDDMMYY.ext

The desire was for a rule at domain.ext/.htaccess to catch the
minority links when they come from elsewhere and redirect to
string1.domain.ext/filenameDDMMYY.ext

Reese



------------------------------------------------------------ ---------
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: Rewrite Voodoo pt. 2

am 23.01.2010 22:10:45 von Eric Covener

On Sat, Jan 23, 2010 at 3:56 PM, Reese wrote:
> On 23-Jan-10 10:38, Eric Covener wrote:
>
>> What's the full input URL that you're matching?
>
> The majority of links use string1.domain.ext/filenameDDMMYY.ext but
> a minority of links use www.domain.ext/string1/filenameDDMMYY.ext
>
> The desire was for a rule at domain.ext/.htaccess to catch the
> minority links when they come from elsewhere and redirect to
> string1.domain.ext/filenameDDMMYY.ext
>

Those aren't URLs.

The last rule you proposed is a no-op, because the pattern in your
RewriteRule is compared to the string "string1/filenameDDMMYY.ext" and
not to any longer string such as
"www.domain.ext/string1/filenameDDMMYY.ext" or
"http://www.domain.ext/string1/filenameDDMMYY.ext"


--
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: Rewrite Voodoo pt. 2

am 25.01.2010 18:02:54 von Oliver Schoenborn

> Can you interpret:
>>=20
>> rewriteCond $(HOST_NAME) ^(.*)\.domain\.ext
>=20
> Condition, proceed for host_name matching (anySubdomain).domain.ext
>=20
>> rewriteRule ^(.*)$ $(HOST_NAME)$1
>=20
> Rule, I'm not sure what it does. Based on the link Tom posted, I'd
> guess that it takes everything after domain.ext and appends it after
> domain.ext - which would take an incoming URI request and output the
> URI unchanged. But that's my guess. I don't *know* what it does for
> sure. I could create a sandbox and test, but somehow that seems like
> it would be cheating.

This has come up a few times in this thread: you must remember that the URL=
does NOT include the domain name. Therefore, the above rule takes the whol=
e URL from beginning to end and *prepends* the hostname so that in the subs=
equent rule (not shown above), you can also extract parts of the host name =
(since parts are needed for rewritten the URL).=20

> rewriteRule ^([a-z])(.*)([0-9])\.domain\.ext(.*) www$3.domain.ext/$2_$1$4
>=20
> Rule,
> lowercase-alpha saved as $1
> plus
> zero or more of everything saved as $2
> plus
> 0-9 numeric saved as $3
> plus
> domain.ext
> plus
> zero or more of anything saved as $4
>=20
> rewrite to
> www$3.domain.ext/$2_$1$4

You got it so far...

> In the case of www.domain.ext/subdomain/file220110.html this would
> result in a severely fractured URL I think.

I was just given an example of how parts of the domain name can be extracte=
d and put in URL path with proper rules and conditions.=20

>> What will it do to the following HTTP requests:
>=20
> Oh wow. Here we go. For URI's that match host_name:
>=20
> rewriteRule ^([a-z])(.*)([0-9])\.domain\.ext(.*) www$3.domain.ext/$2_$1$4
>=20
>> domain.ext/something
>=20
> www.domain.ext/something

Wrong: www.domain.ext does not match the condition so everything is skipped=
(I might have forgotten a [C] on the first rule, sorry, didn't test)

>=20
>> asub2.domain.ext/something
>=20
> www.domain.ext/2_asubsomething

You correctly parsed the rule earlier, according to which it would be=20

www2.domain.ext/sub_asomething

but don't forget that there would actually be a slash right after the sub_a=
since something will always start with a slash (except maybe in .htacces r=
ules?)

>> asub.domain.ext/something
>=20
> www.domain.ext/_asubsomething
>=20
> I think.

Wrong: the pattern for 2nd rule requires a digit just before the first dot =
of host name, so rule will get skipped and URL unchanged. =20

>=20
> Reese
>=20

It's really important to understand how the conditions and pattern matching=
work, together with regexp. There may be other issues to consider when the=
rule is in an .htaccess (I gather you only get part of the URL path then).=
=20

Oliver=

------------------------------------------------------------ ---------
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: Rewrite Voodoo pt. 2

am 25.01.2010 18:44:13 von Reese

On 25-Jan-10 12:02, Oliver Schoenborn wrote:

> It's really important to understand how the conditions and pattern matching work, together with regexp. There may be other issues to consider when the rule is in an .htaccess (I gather you only get part of the URL path then).


I'm familiar with The Regex Coach, have it installed and use it from
time to time: http://weitz.de/regex-coach/

I wonder what it would take to make something similar for mod_rewrite.
Or if something like that already exists, just needs more publicity.

Reese


------------------------------------------------------------ ---------
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: Rewrite Voodoo pt. 2

am 26.01.2010 23:07:23 von Reese

I've been rolling everything that has been said around in my head,
and now I'm wondering why something like the below would not work:

RewriteEngine On
RewriteCond (/sring1/)
RewriteRule ^%(HTTP_HOST)/(string1)/(.*)% $2\.domain\.ext/$3


Or am I just not getting it still?

Reese


------------------------------------------------------------ ---------
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: Rewrite Voodoo pt. 2

am 26.01.2010 23:21:07 von Frank Gingras

On 01/26/2010 05:07 PM, Reese wrote:
> I've been rolling everything that has been said around in my head,
> and now I'm wondering why something like the below would not work:
>
> RewriteEngine On
> RewriteCond (/sring1/)
> RewriteRule ^%(HTTP_HOST)/(string1)/(.*)% $2\.domain\.ext/$3
>
>
> Or am I just not getting it still?
>
> Reese
>
>
> ------------------------------------------------------------ ---------
> 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
>

You can't use %(HTTP_HOST) in the matching portion of the rule.

Frank.

------------------------------------------------------------ ---------
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: Rewrite Voodoo pt. 2

am 26.01.2010 23:55:14 von Reese

On 26-Jan-10 17:21, Frank Gingras wrote:

> You can't use %(HTTP_HOST) in the matching portion of the rule.

Dang. How about this?

RewriteEngine On
RewriteCond %{HOST_HTTP} (www\.)?domain.ext/string1/
RewriteRule ^/(string1)/(.*)$ $2\.domain\.ext/$3 [R=301,L]

Reese



------------------------------------------------------------ ---------
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: Rewrite Voodoo pt. 2

am 27.01.2010 00:12:23 von Reese

On 26-Jan-10 17:55, Reese wrote:

> How about this?
>
> RewriteEngine On
> RewriteCond %{HOST_HTTP} (www\.)?domain.ext/string1/
> RewriteRule ^/(string1)/(.*)$ $2\.domain\.ext/$3 [R=301,L]


I'm having 2nd thoughts on that. How about this one?

RewriteEngine On
RewriteCond %{HOST_HTTP} (www\.)?domain.ext
RewriteRule ^/(string1)/(.*)$ $2\.domain\.ext/$3 [R=301,L]

Reese


------------------------------------------------------------ ---------
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: Rewrite Voodoo pt. 2

am 27.01.2010 01:41:22 von Eric Covener

On Tue, Jan 26, 2010 at 6:12 PM, Reese wrote:
> RewriteEngine On
> RewriteCond %{HOST_HTTP} (www\.)?domain.ext
> RewriteRule ^/(string1)/(.*)$ $2\.domain\.ext/$3 [R=301,L]
>

Much closer to being reasonable.

You have more backreferences ($1, $2, $3) then you have captures. You
probably want something closer to this

RewriteCond %{HTTP_HOST} (www\.)?domain.ext
RewriteRule ^/(subdomain1|subdomain2|subdomain3)/(.*)
http://$1.domain.ext/$2 [R=301,L]

Which fixes a few other nits (variable name transposed, prefix
redirect with protocol)

I explicitly listed subdomains/subdirs to avoid capturing subdirs of
the docroot that don't happen map to other domains.

--
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: Rewrite Voodoo pt. 2

am 27.01.2010 02:06:40 von Reese

On 26-Jan-10 19:41, Eric Covener wrote:
> On Tue, Jan 26, 2010 at 6:12 PM, Reese wrot=
e:
>> RewriteEngine On
>> RewriteCond %{HOST_HTTP} (www\.)?domain.ext
>> RewriteRule ^/(string1)/(.*)$ $2\.domain\.ext/$3 [R=3D301,L]
>>
>=20
> Much closer to being reasonable.
>=20
> You have more backreferences ($1, $2, $3) then you have captures. You
> probably want something closer to this
>=20
> RewriteCond %{HTTP_HOST} (www\.)?domain.ext
> RewriteRule ^/(subdomain1|subdomain2|subdomain3)/(.*)
> http://$1.domain.ext/$2 [R=3D301,L]
>=20
> Which fixes a few other nits (variable name transposed, prefix
> redirect with protocol)
>=20
> I explicitly listed subdomains/subdirs to avoid capturing subdirs of
> the docroot that don't happen map to other domains.

Obviously I'm still missing something, because that just looks borken
to me. But, at this juncture I will rise up from my lethargic backside
and do some testing on a server - one where if it backfires on me, it
won't take live pages offline.

If you were local to me, I'd offer you a cookie. Chocolate chip, fresh
from the oven. It's hard to beat "fresh from the oven" from a cook who
knows how to saut=E9e garlic w/out burning it - and can make Julia Child'=
s
boeuf bourguignon successfully and repetitiously. ;)
I need more exercise - of the physical kind. :(

Reese




------------------------------------------------------------ ---------
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: Rewrite Voodoo pt. 2

am 27.01.2010 03:37:12 von Oliver Schoenborn

I love chocolate chip cookies....

________________________________________
From: Reese [howell.r@inkworkswell.com]
Sent: Tuesday, January 26, 2010 8:06 PM
To: users@httpd.apache.org
Subject: Re: [users@httpd] Rewrite Voodoo pt. 2

....

If you were local to me, I'd offer you a cookie. Chocolate chip, fresh
from the oven.=20
Reese=

------------------------------------------------------------ ---------
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: Rewrite Voodoo pt. 2

am 27.01.2010 03:42:26 von Reese

On 26-Jan-10 21:37, Oliver Schoenborn wrote:
> I love chocolate chip cookies....

You helped too, so why not? ;)

Reese


------------------------------------------------------------ ---------
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