niXforums Forum Index
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   PreferencesPreferences   Log in to check your private messagesLog in to check your private messages   Log inLog in 
·  nixdoc.net ·  man pages ·  Linux HOWTOs ·  FreeBSD Tips ·  Forums
navigation Forum index » Apps » Apache
mod_rewrite with [last] not behaving as expected
Post new topic   Reply to topic Page 1 of 1 [6 Posts] View previous topic :: View next topic
Author Message
Nick Burch
*nix forums beginner


Joined: 06 Dec 2005
Posts: 11

PostPosted: Thu Jul 20, 2006 9:49 am    Post subject: mod_rewrite with [last] not behaving as expected Reply with quote

Hi All

I've been trying to set up some rewriting rules with mod_rewrite, and
discovered that even with a [last] directive, things aren't quite behaving
as I'd expect.

My config is perhaps slightly unusual, in that I have a default rule that
applies, at the bottom of the rewrite block. The config is something like:

DocumentRoot /var/www/foo/
<Directory /var/www/foo/>
RewriteEngine on
RewriteRule ^foo/foo.xsd /schema/foo.xsd [last]
RewriteRule ^foo/.* /schema/about_foo.html [last]
RewriteRule .* http://somewhere-else/ [R]
</Directory>

Turning on RewriteLog and RewriteLogLevel, I see that a request for
/foo/bar is re-written as an internal redirect to /schema/about_foo.html.
No further rewriting occurs. The problem is that apache decides that it
then needs to start processing /schema/about_foo.html from the top of my
rewriting block, since it too falls within the Directory. It then runs
off, does more rewriting, and goes to the wrong place.

In short, the [last] directive stops this re-writing run, but doesn't
prevent further runs.

Is this behaviour:
a) expected (except by me!) or unexpected?
b) if expected, should we add another mod_rewrite flag to prevent further
mod_rewrites touching the request? (eg [nofurther])

(For anyone suffering the same issue, my workaround was to add a
<Directory> for the schema subdir, with RewriteEngine on, but no rules)

Nick

---------------------------------------------------------------------
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
Back to top
Neil A. Hillard
*nix forums addict


Joined: 09 Mar 2005
Posts: 77

PostPosted: Thu Jul 20, 2006 10:01 am    Post subject: Re: mod_rewrite with [last] not behaving as expected Reply with quote

Nick,

Nick Burch wrote:
Quote:
Hi All

I've been trying to set up some rewriting rules with mod_rewrite, and
discovered that even with a [last] directive, things aren't quite
behaving as I'd expect.

My config is perhaps slightly unusual, in that I have a default rule
that applies, at the bottom of the rewrite block. The config is
something like:

DocumentRoot /var/www/foo/
Directory /var/www/foo/
RewriteEngine on
RewriteRule ^foo/foo.xsd /schema/foo.xsd [last]
RewriteRule ^foo/.* /schema/about_foo.html [last]
RewriteRule .* http://somewhere-else/ [R]
/Directory

Turning on RewriteLog and RewriteLogLevel, I see that a request for
/foo/bar is re-written as an internal redirect to
/schema/about_foo.html. No further rewriting occurs. The problem is that
apache decides that it then needs to start processing
/schema/about_foo.html from the top of my rewriting block, since it too
falls within the Directory. It then runs off, does more rewriting, and
goes to the wrong place.

In short, the [last] directive stops this re-writing run, but doesn't
prevent further runs.

Is this behaviour:
a) expected (except by me!) or unexpected?
b) if expected, should we add another mod_rewrite flag to prevent further
mod_rewrites touching the request? (eg [nofurther])

(For anyone suffering the same issue, my workaround was to add a
Directory> for the schema subdir, with RewriteEngine on, but no rules)

Yes it is expected - it is not Apache deciding to run the URL through
the rewriting. A redirect will be sent to the client which will then
request the new target and it is that which will be run through the
rewriting rules.

I would suggest that you'd be better off with rewriting in a Location
block and not a Directory. The rewriting relates to the URL and not
necessarily the file system.

If you retain those rewrites then every request will end up at
http://somewhere-else/.

Do you really want to perform a redirect - in which case you need to
exclude /schema/ from 'catchall' last rewrite, or you need to proxy them
(use [P,L]).

HTH,


Neil.

--
Neil Hillard neil.hillard@agustawestland.com
Westland Helicopters Ltd. http://www.whl.co.uk/

Disclaimer: This message does not necessarily reflect the
views of Westland Helicopters Ltd.

---------------------------------------------------------------------
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
Back to top
Chappidi, Sudhakar
*nix forums beginner


Joined: 29 May 2006
Posts: 4

PostPosted: Thu Jul 20, 2006 10:47 am    Post subject: Apache 2.0 appending some extra lines Reply with quote

Hello All,

I have some problem with Apache2.0 while sending the response.
When accessing the request from the browser , the response sent is got
properly.
But when I am using a C++ program for sending and receiving the response
I am getting the response with some addional text appended.
The addition text appended is

"<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>200 OK</title>
</head><body>
<h1>OK</h1>
<p>The server encountered an internal error or
misconfiguration and was unable to complete
your request.</p>
<p>Please contact the server administrator,
you@your.address and inform them of the time the error occurred,
and anything you might have done that may have
caused the error.</p>
<p>More information about this error may be available
in the server error log.</p>
<hr>
<address>Apache/2.0.55 (Win32) mod_jk/1.2.6 Server at dpe1w023 Port
2906</address>
</body></html>
"

In think in case of IE, IE is parsing the response and displaying the
file properly.

Thanks,
Sudhakar

---------------------------------------------------------------------
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
Back to top
Pid
*nix forums beginner


Joined: 19 Jun 2006
Posts: 32

PostPosted: Thu Jul 20, 2006 10:52 am    Post subject: Re: Apache 2.0 appending some extra lines Reply with quote

it looks like you've enabled the custom ErrorDocument directive for the
200 error code.

try disabling it.



Chappidi, Sudhakar wrote:
Quote:


Hello All,

I have some problem with Apache2.0 while sending the response.
When accessing the request from the browser , the response sent is got
properly.
But when I am using a C++ program for sending and receiving the response
I am getting the response with some addional text appended.
The addition text appended is

"<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"
html><head
title>200 OK</title
/head><body
h1>OK</h1
p>The server encountered an internal error or
misconfiguration and was unable to complete
your request.</p
p>Please contact the server administrator,
you@your.address and inform them of the time the error occurred,
and anything you might have done that may have
caused the error.</p
p>More information about this error may be available
in the server error log.</p
hr
address>Apache/2.0.55 (Win32) mod_jk/1.2.6 Server at dpe1w023 Port
2906</address
/body></html
"

In think in case of IE, IE is parsing the response and displaying the
file properly.

Thanks,
Sudhakar

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




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


Joined: 06 Dec 2005
Posts: 11

PostPosted: Fri Jul 21, 2006 9:14 am    Post subject: Re: mod_rewrite with [last] not behaving as expected Reply with quote

On Thu, 20 Jul 2006, Neil A. Hillard wrote:
Quote:
Yes it is expected - it is not Apache deciding to run the URL through
the rewriting. A redirect will be sent to the client which will then
request the new target and it is that which will be run through the
rewriting rules.

This is with an internal redirect though, not an external one. No redirect
is sent to the client, it's all handled within apache.

In the rewrite logs, you do get:
applying pattern
applying pattern
old path -> new path
[INTERNAL REDIRECT]
applying pattern
applying pattern
applying pattern
applying pattern
new path -> catchall

Quote:
I would suggest that you'd be better off with rewriting in a Location
block and not a Directory. The rewriting relates to the URL and not
necessarily the file system.

I'm not suggesting that my current rewriting scheme is optimal, just that
things aren't behaving as expected

Nick

---------------------------------------------------------------------
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
Back to top
Robert Ionescu
*nix forums addict


Joined: 09 Nov 2005
Posts: 64

PostPosted: Fri Jul 21, 2006 12:49 pm    Post subject: Re: mod_rewrite with [last] not behaving as expected Reply with quote

Nick Burch wrote:
Quote:
On Thu, 20 Jul 2006, Neil A. Hillard wrote:
[...]
This is with an internal redirect though, not an external one. No
redirect is sent to the client, it's all handled within apache.

In the rewrite logs, you do get:
applying pattern
applying pattern
old path -> new path
[INTERNAL REDIRECT]
applying pattern
applying pattern
applying pattern
applying pattern
new path -> catchall

I would suggest that you'd be better off with rewriting in a Location
block

This is unsupported. Location is per-dir context, too, while the per-dir
prefix isn't striped. You're matching against the full physical path.
Use it in per-server context instead.

Quote:
I'm not suggesting that my current rewriting scheme is optimal, just
that things aren't behaving as expected

This is how things are working in per-dir context. It stops the
rewriting immediately, but there is a request re-processing and if the
request reaches your RewriteRules again, they're being processed again.

--
Robert

---------------------------------------------------------------------
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
Back to top
Google

Back to top
Display posts from previous:   
Post new topic   Reply to topic Page 1 of 1 [6 Posts] View previous topic :: View next topic
The time now is Thu Dec 04, 2008 2:18 am | All times are GMT
navigation Forum index » Apps » Apache
Jump to:  

Similar Topics
Topic Author Forum Replies Last Post
No new posts mod_rewrite to go from http to https and back sevans@bigskypenguin.com Apache 0 Fri Jul 21, 2006 5:12 am
No new posts mod_rewrite question. Vincent Blondel Apache 0 Wed Jul 19, 2006 9:06 am
No new posts expected unqualified-id before "." token? Thomas Barth C++ 3 Tue Jul 18, 2006 12:42 pm
No new posts mod_rewrite and mod_cache Tom Hodder Apache 2 Tue Jul 11, 2006 6:44 pm
No new posts FW: Re: problem with mod_rewrite rewiterule with [P](inte... Axel-Stéphane SMORGRAV Apache 0 Mon Jul 10, 2006 5:06 pm

Remortgages | Mortgage Calculator | Myspace Layouts | Home Loan | Myspace Proxy
Copyright © 2004-2005 DeniX Solutions SRL
 
Other DeniX Solutions sites: Unix/Linux blog |  electronics forum |  medicine forum |  science forum | 
Privacy Policy


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 4.6692s ][ Queries: 16 (4.3657s) ][ GZIP on - Debug on ]