You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Tapas Mishra <mi...@gmail.com> on 2010/06/15 14:42:46 UTC

[users@httpd] rewrite rule tutorial on ask apache I could not understand syntax

http://http://www.askapache.com/htaccess/crazy-advanced-mod_rewrite-tutorial.html

 is a link to a tutorial which mentions following use of ReWriteRule is wrong.

RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_HOST} !^www\.askapache\.com$ [NC]
RewriteRule .+ http://www.askapache.com%{REQUEST_URI}

I could not understand what is the mistake in the above rule?
Can some one point what is the error which the tutorial is trying to tell.

-- 
Tapas
http://mightydreams.blogspot.com
http://wiki.xensource.com/xenwiki/Xen_on_4_app_servers

---------------------------------------------------------------------
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] rewrite rule tutorial on ask apache I could not understand syntax

Posted by Tapas Mishra <mi...@gmail.com>.
Hi,Tom and Rich thanks for your links.Can you provide any more link as
what exactly can I do more with Apache.
I have hosted websites and know some bit of reverse proxy etc.
>From this discussion I got curiosity to understand the hooking process
of apache.Can you provide me some links which you feel can be of help
to me,
and what more can I do with Apache.

On Thu, Jun 17, 2010 at 7:49 AM, Rich Bowen <rb...@rcbowen.com> wrote:
>
> On Jun 15, 2010, at 8:42 AM, Tapas Mishra wrote:
>
>>
>> http://http://www.askapache.com/htaccess/crazy-advanced-mod_rewrite-tutorial.html
>>
>> is a link to a tutorial which mentions following use of ReWriteRule is
>> wrong.
>
> Anything found on askapache.com should be taken with a great deal of
> skepticism. His site is full of things which are either completely wrong,
> or, at best, recommend bad practices. It's doubly frustrating because he's
> actively resisted correction, insisting that he's right when he's not, and
> perpetuating awful practices years after they have been demonstrated to be a
> bad idea. There was a time when it seemed feasible that he'd come around to
> better ideas, but he seems more interested in insisting that he's right than
> actually *being* right.
>
> --
> Rich Bowen
> rbowen@rcbowen.com
>
>
>
>
> ---------------------------------------------------------------------
> 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
>
>



-- 
Tapas
http://mightydreams.blogspot.com
http://wiki.xensource.com/xenwiki/Xen_on_4_app_servers

---------------------------------------------------------------------
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] rewrite rule tutorial on ask apache I could not understand syntax

Posted by Rich Bowen <rb...@rcbowen.com>.
On Jun 15, 2010, at 8:42 AM, Tapas Mishra wrote:

> http://http://www.askapache.com/htaccess/crazy-advanced-mod_rewrite-tutorial.html
>
> is a link to a tutorial which mentions following use of ReWriteRule  
> is wrong.

Anything found on askapache.com should be taken with a great deal of  
skepticism. His site is full of things which are either completely  
wrong, or, at best, recommend bad practices. It's doubly frustrating  
because he's actively resisted correction, insisting that he's right  
when he's not, and perpetuating awful practices years after they have  
been demonstrated to be a bad idea. There was a time when it seemed  
feasible that he'd come around to better ideas, but he seems more  
interested in insisting that he's right than actually *being* right.

--
Rich Bowen
rbowen@rcbowen.com




---------------------------------------------------------------------
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] rewrite rule tutorial on ask apache I could not understand syntax

Posted by Tapas Mishra <mi...@gmail.com>.
On Mon, Jun 21, 2010 at 1:14 PM, Matus UHLAR - fantomas
<uh...@fantomas.sk> wrote:
> can you tell usa what are you trying to do?
I am trying to understand what ever was written on tutorial.

Nothing else.Since I could not understand so I posted.

---------------------------------------------------------------------
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] rewrite rule tutorial on ask apache I could not understand syntax

Posted by Matus UHLAR - fantomas <uh...@fantomas.sk>.
On 15.06.10 18:12, Tapas Mishra wrote:
> http://http://www.askapache.com/htaccess/crazy-advanced-mod_rewrite-tutorial.html
> 
>  is a link to a tutorial which mentions following use of ReWriteRule is wrong.
> 
> RewriteEngine On
> RewriteBase /
> 
> RewriteCond %{HTTP_HOST} !^www\.askapache\.com$ [NC]
> RewriteRule .+ http://www.askapache.com%{REQUEST_URI}
> 
> I could not understand what is the mistake in the above rule?
> Can some one point what is the error which the tutorial is trying to tell.

can you tell usa what are you trying to do? Seems as another attempt to do
simple HTTP redirect to www.askapache.com if host is not www.askapache.com.

This can be done by using third party plugins that can redirect to canonical
name (mod_redirtoservname or mod_common_redirect), or by using name-based
virtual hosting, with the first (default) virtual host redirecting to second
one, with ServerName www.askapache.com and no ServerAlias.


-- 
Matus UHLAR - fantomas, uhlar@fantomas.sk ; http://www.fantomas.sk/
Warning: I wish NOT to receive e-mail advertising to this address.
Varovanie: na tuto adresu chcem NEDOSTAVAT akukolvek reklamnu postu.
Your mouse has moved. Windows NT will now restart for changes to take
to take effect. [OK]

---------------------------------------------------------------------
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] rewrite rule tutorial on ask apache I could not understand syntax

Posted by Tom Evans <te...@googlemail.com>.
On Tue, Jun 15, 2010 at 1:42 PM, Tapas Mishra <mi...@gmail.com> wrote:
> http://http://www.askapache.com/htaccess/crazy-advanced-mod_rewrite-tutorial.html
>
>  is a link to a tutorial which mentions following use of ReWriteRule is wrong.
>
> RewriteEngine On
> RewriteBase /
>
> RewriteCond %{HTTP_HOST} !^www\.askapache\.com$ [NC]
> RewriteRule .+ http://www.askapache.com%{REQUEST_URI}
>
> I could not understand what is the mistake in the above rule?
> Can some one point what is the error which the tutorial is trying to tell.
>

I don't know what he's smoking, I use a rule almost identical to that
in many places.
Perhaps it behaves differently in .htaccess configuration, which is
what he is describing.

The rule I use on a daily basis:

RewriteCond %{HTTP_HOST} !^(altname\.example\.com|name\.example\.com)$
RewriteRule ^/(.*)  http://name.example.com/$1 [R=301,L]

Also, his point about not being able to see what the various variables
are, I kind of see his point, it would be nice to have examples of
what the variables could be, but you can always turn on the rewrite
log to see stuff like that.

Cheers

Tom

---------------------------------------------------------------------
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] rewrite rule tutorial on ask apache I could not understand syntax

Posted by Eric Covener <co...@gmail.com>.
On Tue, Jun 15, 2010 at 9:39 AM, Tom Evans <te...@googlemail.com> wrote:
> On Tue, Jun 15, 2010 at 2:19 PM, Eric Covener <co...@gmail.com> wrote:
>> Who can guess if that silly page meant either of these subtle issues
>> with the recipe:
>>
>> *) ".+" in .htaccess won't match a request for "/", but I doubt that's
>> the operative part of the exercise.
>> *) You Should not redirect if HTTP_HOST is empty, for HTTP/1.0
>> clients, or you might loop.
>>
>> --
>> Eric Covener
>> covener@gmail.com
>>
>
> Hi Eric
>
> wrt your second point, it's been my understanding that if you are
> using name based virtual hosting, then HTTP/1.0 clients will always be
> directed to the first virtual host, and so it is fine to not check for
> empty HTTP_HOST in name based virtual hosts, when canonicalizing the
> host name. Is this accurate?
>

not sure -- may not be a practical concern for the reasons you
describe (and I didn't test that aspect)

--
Eric Covener
covener@gmail.com

---------------------------------------------------------------------
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] rewrite rule tutorial on ask apache I could not understand syntax

Posted by Tom Evans <te...@googlemail.com>.
On Tue, Jun 15, 2010 at 2:19 PM, Eric Covener <co...@gmail.com> wrote:
> Who can guess if that silly page meant either of these subtle issues
> with the recipe:
>
> *) ".+" in .htaccess won't match a request for "/", but I doubt that's
> the operative part of the exercise.
> *) You Should not redirect if HTTP_HOST is empty, for HTTP/1.0
> clients, or you might loop.
>
> --
> Eric Covener
> covener@gmail.com
>

Hi Eric

wrt your second point, it's been my understanding that if you are
using name based virtual hosting, then HTTP/1.0 clients will always be
directed to the first virtual host, and so it is fine to not check for
empty HTTP_HOST in name based virtual hosts, when canonicalizing the
host name. Is this accurate?

Cheers

Tom

---------------------------------------------------------------------
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] rewrite rule tutorial on ask apache I could not understand syntax

Posted by Tom Evans <te...@googlemail.com>.
On Tue, Jun 15, 2010 at 3:56 PM, Tapas Mishra <mi...@gmail.com> wrote:
> On Tue, Jun 15, 2010 at 8:16 PM, Tom Evans <te...@googlemail.com> wrote:
>>
>> I dont understand what you are asking? - the reply comes from apache.
> I could not understand I am newcomer to apache.I have used Reverse
> Proxy and other settings but do not completely understand it.
> So trying to understand how apache behaves when it gets a request to
> serve a webpage what is happening in background.
>
>> HTTP_HOST is a variable that holds the value of the http header
>> 'Host'. If the browser doesn't send one, it isn't going to have a
>> value.
>
> What is Host in this reply which you are referring to.
>

Host is a request header sent with HTTP/1.1 requests indicating the
host that the user requested.
Apache reads that header in and stores it on the request.
mod_rewrite makes that variable available to read with the name HTTP_HOST.

If the request is a HTTP/1.0 request, no host header is sent, so
HTTP_HOST will be empty if examined.

I can't explain the HTTP protocol + Apache on a mailing list. Do what
I did and read RFC 2616 to understand HTTP, and read "Apache modules
with Perl and C" to understand Apache (although it is a little dated
now, it has an excellent section on the request life cycle). This may
also help:

http://stein.cshl.org/~lstein/talks/perl_conference/apache_api/lifecycle.html

Tom

---------------------------------------------------------------------
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] rewrite rule tutorial on ask apache I could not understand syntax

Posted by Tapas Mishra <mi...@gmail.com>.
On Tue, Jun 15, 2010 at 8:16 PM, Tom Evans <te...@googlemail.com> wrote:
>
> I dont understand what you are asking? - the reply comes from apache.
I could not understand I am newcomer to apache.I have used Reverse
Proxy and other settings but do not completely understand it.
So trying to understand how apache behaves when it gets a request to
serve a webpage what is happening in background.

> HTTP_HOST is a variable that holds the value of the http header
> 'Host'. If the browser doesn't send one, it isn't going to have a
> value.

What is Host in this reply which you are referring to.

-- 
Tapas
http://mightydreams.blogspot.com
http://wiki.xensource.com/xenwiki/Xen_on_4_app_servers

---------------------------------------------------------------------
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] rewrite rule tutorial on ask apache I could not understand syntax

Posted by Tom Evans <te...@googlemail.com>.
On Tue, Jun 15, 2010 at 3:41 PM, Tapas Mishra <mi...@gmail.com> wrote:
>>
>> HTTP/1.0 clients do not send a Host header in the request
>>  => no host information can be inferred from a request
>>  => HTTP_HOST will be empty.
> but if HTTP_HOST is empty then from where is the reply coming from ?
>

I dont understand what you are asking? - the reply comes from apache.
HTTP_HOST is a variable that holds the value of the http header
'Host'. If the browser doesn't send one, it isn't going to have a
value.

Tom

---------------------------------------------------------------------
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] rewrite rule tutorial on ask apache I could not understand syntax

Posted by Tapas Mishra <mi...@gmail.com>.
>
> HTTP/1.0 clients do not send a Host header in the request
>  => no host information can be inferred from a request
>  => HTTP_HOST will be empty.
but if HTTP_HOST is empty then from where is the reply coming from ?


-- 
Tapas
http://mightydreams.blogspot.com
http://wiki.xensource.com/xenwiki/Xen_on_4_app_servers

---------------------------------------------------------------------
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] rewrite rule tutorial on ask apache I could not understand syntax

Posted by Tom Evans <te...@googlemail.com>.
On Tue, Jun 15, 2010 at 3:33 PM, Tapas Mishra <mi...@gmail.com> wrote:
> On Tue, Jun 15, 2010 at 6:49 PM, Eric Covener <co...@gmail.com> wrote:
>
>> *) You Should not redirect if HTTP_HOST is empty, for HTTP/1.0
>> clients, or you might loop.
>
>  I could not understand your statement HTTP_HOST empty can you be a
> bit explanatory.It will help newbies like me.
>

HTTP/1.0 clients do not send a Host header in the request
  => no host information can be inferred from a request
  => HTTP_HOST will be empty.

Cheers

Tom

---------------------------------------------------------------------
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] rewrite rule tutorial on ask apache I could not understand syntax

Posted by Tapas Mishra <mi...@gmail.com>.
On Tue, Jun 15, 2010 at 6:49 PM, Eric Covener <co...@gmail.com> wrote:

> *) You Should not redirect if HTTP_HOST is empty, for HTTP/1.0
> clients, or you might loop.

 I could not understand your statement HTTP_HOST empty can you be a
bit explanatory.It will help newbies like me.

-- 
Tapas
http://mightydreams.blogspot.com
http://wiki.xensource.com/xenwiki/Xen_on_4_app_servers

---------------------------------------------------------------------
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] rewrite rule tutorial on ask apache I could not understand syntax

Posted by Eric Covener <co...@gmail.com>.
On Tue, Jun 15, 2010 at 8:42 AM, Tapas Mishra <mi...@gmail.com> wrote:
> http://http://www.askapache.com/htaccess/crazy-advanced-mod_rewrite-tutorial.html
>
>  is a link to a tutorial which mentions following use of ReWriteRule is wrong.
>
> RewriteEngine On
> RewriteBase /
>
> RewriteCond %{HTTP_HOST} !^www\.askapache\.com$ [NC]
> RewriteRule .+ http://www.askapache.com%{REQUEST_URI}
>
> I could not understand what is the mistake in the above rule?
> Can some one point what is the error which the tutorial is trying to tell.

Who can guess if that silly page meant either of these subtle issues
with the recipe:

*) ".+" in .htaccess won't match a request for "/", but I doubt that's
the operative part of the exercise.
*) You Should not redirect if HTTP_HOST is empty, for HTTP/1.0
clients, or you might loop.

-- 
Eric Covener
covener@gmail.com

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