You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Richard Schoenig <Ri...@picis.com> on 2010/03/10 19:42:55 UTC
[users@httpd] rewrite rule
I am new to using mod_rewrite and have been trying to create a rule to
do something rather simple, but keep hitting a wall. I have been trying
to research online how to do it, but I keep finding global changes and
not specific to what I am trying to do. Essentially I am looking to use
a rewrite rule to redirect users in an application from
http://server4/perl.pl?n=1 to http://server1/perl.pl?n=1
I tried using
RewriteEngine on
Options +FollowSymlinks
RewriteCond %{QUERY_STRING} ^n=1$
RewriteRule ^$ http://127.0.0.1/ perl.pl [L]
RewriteCond %{QUERY_STRING} ^n=2$
RewriteRule ^$ http://127.0.0.1/ perl.pl [L]
RewriteCond %{QUERY_STRING} ^n=3$
RewriteRule ^$ http://mypcname/perl.pl [L]
To test on my local host but I am guessing that it is not even close to
what I want to do.
The information in this email is confidential and may be legally privileged. It is intended solely for the addressee. Access or use by any other person to this internet email is not authorized and may be unlawful. If you are not the intended recipient, please delete or destroy this email. If you do not wish to receive future emails from this sender, please reply directly to this email requesting you be removed from any mailing list.
Re: [users@httpd] rewrite rule
Posted by Philip Wigg <ph...@philipwigg.co.uk>.
On 11 March 2010 15:56, Richard Schoenig <Ri...@picis.com> wrote:
> So here is the issue I am having now I have separate servers I am trying to
> set this rule up on so that if a n=1 or an n=2 it accesses server 1, and if
> an n=3 then it accesses server 2
>
>
>
> The rules I have setup are on server 2 I have it configured like this
>
> <IfModule mod_rewrite.c>
>
> RewriteEngine on
>
> Options +FollowSymlinks
>
> RewriteCond %{QUERY_STRING} ^(n=[1-2]+)$
>
> RewriteRule ^/perl.pl$ http://server1/perl.pl?%1 [R,L]
>
> </IfModule>
>
>
>
> This seems to work fine and redirects to server 1 the way I want.
>
>
>
> However on server 1 I have it configured with
>
> <IfModule mod_rewrite.c>
>
> RewriteEngine on
>
> Options +FollowSymlinks
>
> RewriteCond %{QUERY_STRING} ^(n=[3]+)$
>
> RewriteRule ^/perl.pl$ http://server2/perl.pl?%1 [R,L]
>
> </IfModule>
> As I said server 2 seems to work fine, but server 1 I cannot seem to get to
> work at all it seems to get in a loop and does nothing.
Debugging mod_rewrite rules is much easier if you configure a
RewriteLog so you can see what mod_rewrite is actually doing:-
http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html#rewritelog
Also try using curl, fiddler, firebug or some other tool to actually
see what responses you're getting from the server when you make a
request.
-- Phil
---------------------------------------------------------------------
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
Posted by Igor Cicimov <ic...@gmail.com>.
Just put ^(n=3)$ and it will work
On Mar 12, 2010 3:34 AM, "Francis GALIEGUE" <fg...@one2team.com> wrote:
On Thu, Mar 11, 2010 at 16:56, Richard Schoenig
<Ri...@picis.com> wrote:
> So here is the issue I am having now I have separate servers I am trying
to > set this rule up on ...
[...]
> RewriteCond %{QUERY_STRING} ^(n=[3]+)$
Why [3]+? 3+ is largely enough. 3 is an atom, like any character
class. And it will match 3, 33, 333, etc, whether it is written [3]+
or 3+, so this is probably not what you want.
Remember that quantifiers (+, *, {...}) apply to the immediately preceding
atom.
--
Francis Galiegue
ONE2TEAM
Ingénieur système
Mob : +33 (0) 683 877 875
Tel : +33 (0) 178 945 552
fge@one2team.com
40 avenue Raymond Poincaré
75116 Paris
--------------------------------------------------------------------- The
official User-To-User sup...
Re: [users@httpd] rewrite rule
Posted by Francis GALIEGUE <fg...@one2team.com>.
On Thu, Mar 11, 2010 at 16:56, Richard Schoenig
<Ri...@picis.com> wrote:
> So here is the issue I am having now I have separate servers I am trying to
> set this rule up on so that if a n=1 or an n=2 it accesses server 1, and if
> an n=3 then it accesses server 2
>
[...]
> RewriteCond %{QUERY_STRING} ^(n=[3]+)$
Why [3]+? 3+ is largely enough. 3 is an atom, like any character
class. And it will match 3, 33, 333, etc, whether it is written [3]+
or 3+, so this is probably not what you want.
Remember that quantifiers (+, *, {...}) apply to the immediately preceding atom.
--
Francis Galiegue
ONE2TEAM
Ingénieur système
Mob : +33 (0) 683 877 875
Tel : +33 (0) 178 945 552
fge@one2team.com
40 avenue Raymond Poincaré
75116 Paris
---------------------------------------------------------------------
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
Posted by Richard Schoenig <Ri...@picis.com>.
So here is the issue I am having now I have separate servers I am trying
to set this rule up on so that if a n=1 or an n=2 it accesses server 1,
and if an n=3 then it accesses server 2
The rules I have setup are on server 2 I have it configured like this
<IfModule mod_rewrite.c>
RewriteEngine on
Options +FollowSymlinks
RewriteCond %{QUERY_STRING} ^(n=[1-2]+)$
RewriteRule ^/perl.pl$ http://server1/perl.pl?%1 [R,L]
</IfModule>
This seems to work fine and redirects to server 1 the way I want.
However on server 1 I have it configured with
<IfModule mod_rewrite.c>
RewriteEngine on
Options +FollowSymlinks
RewriteCond %{QUERY_STRING} ^(n=[3]+)$
RewriteRule ^/perl.pl$ http://server2/perl.pl?%1 [R,L]
</IfModule>
As I said server 2 seems to work fine, but server 1 I cannot seem to get
to work at all it seems to get in a loop and does nothing.
Any and all help would be greatly appreciated.
>From: Igor Cicimov [mailto:icicimov@gmail.com]
>Sent: Thursday, March 11, 2010 12:32 AM
>To: users@httpd.apache.org
>Subject: Re: [users@httpd] rewrite rule
>http://server4/perl.pl?n=1 to http://server1/perl.pl?n=1
>You can't test it on the localhost since you are redirecting some page
to itself => infinite loop
Try redirecting to some imaginary domain or google.com
> RewriteCond %{QUERY_STRING} ^(n=[0-9]+)$
> RewriteRule ^/perl.pl$ http://google.com/perl.pl?%1
<http://google.com/perl.pl?%251> [R,L]
>and if the browser gets back the googles 404 page not found and your
address bar looks like >"http://www.google.com/perl.pl?n=1" => your rule
is good
>Igor
>On Thu, Mar 11, 2010 at 3:56 PM, Nilesh Govindarajan <li...@itech7.com>
wrote:
>On Thu, Mar 11, 2010 at 12:12 AM, Richard Schoenig
><Ri...@picis.com> wrote:
> I am new to using mod_rewrite and have been trying to create a rule to
do
> something rather simple, but keep hitting a wall. I have been trying
to
> research online how to do it, but I keep finding global changes and
not
> specific to what I am trying to do. Essentially I am looking to use a
> rewrite rule to redirect users in an application from
>
>
>
> http://server4/perl.pl?n=1 to http://server1/perl.pl?n=1
>
>
>
>
>
> I tried using
>
> RewriteEngine on
>
> Options +FollowSymlinks
>
> RewriteCond %{QUERY_STRING} ^n=1$
>
> RewriteRule ^$ http://127.0.0.1/ perl.pl [L]
>
> RewriteCond %{QUERY_STRING} ^n=2$
>
> RewriteRule ^$ http://127.0.0.1/ perl.pl [L]
>
> RewriteCond %{QUERY_STRING} ^n=3$
>
> RewriteRule ^$ http://mypcname/perl.pl [L]
>
>
>
>
>
>
>
> To test on my local host but I am guessing that it is not even close
to what
> I want to do.
>
>
>
>
>
> The information in this email is confidential and may be legally
privileged.
> It is intended solely for the addressee. Access or use by any other
person
> to this internet email is not authorized and may be unlawful. If you
are not
> the intended recipient, please delete or destroy this email. If you do
not
> wish to receive future emails from this sender, please reply directly
to
> this email requesting you be removed from any mailing list.
You want to redirect or rewrite ?
--
Nilesh Govindarajan
Site & Server Administrator
www.itech7.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
The information in this email is confidential and may be legally privileged. It is intended solely for the addressee. Access or use by any other person to this internet email is not authorized and may be unlawful. If you are not the intended recipient, please delete or destroy this email. If you do not wish to receive future emails from this sender, please reply directly to this email requesting you be removed from any mailing list.
Re: [users@httpd] rewrite rule
Posted by Igor Cicimov <ic...@gmail.com>.
>
> http://server4/perl.pl?n=1 to http://server1/perl.pl?n=1
>
You can't test it on the localhost since you are redirecting some page to
itself => infinite loop
Try redirecting to some imaginary domain or google.com
RewriteCond %{QUERY_STRING} ^(n=[0-9]+)$
RewriteRule ^/perl.pl$ http://google.com/perl.pl?%1 [R,L]
and if the browser gets back the googles 404 page not found and your address
bar looks like "http://www.google.com/perl.pl?n=1" => your rule is good
Igor
On Thu, Mar 11, 2010 at 3:56 PM, Nilesh Govindarajan <li...@itech7.com>wrote:
> On Thu, Mar 11, 2010 at 12:12 AM, Richard Schoenig
> <Ri...@picis.com> wrote:
> > I am new to using mod_rewrite and have been trying to create a rule to do
> > something rather simple, but keep hitting a wall. I have been trying to
> > research online how to do it, but I keep finding global changes and not
> > specific to what I am trying to do. Essentially I am looking to use a
> > rewrite rule to redirect users in an application from
> >
> >
> >
> > http://server4/perl.pl?n=1 to http://server1/perl.pl?n=1
> >
> >
> >
> >
> >
> > I tried using
> >
> > RewriteEngine on
> >
> > Options +FollowSymlinks
> >
> > RewriteCond %{QUERY_STRING} ^n=1$
> >
> > RewriteRule ^$ http://127.0.0.1/ perl.pl [L]
> >
> > RewriteCond %{QUERY_STRING} ^n=2$
> >
> > RewriteRule ^$ http://127.0.0.1/ perl.pl [L]
> >
> > RewriteCond %{QUERY_STRING} ^n=3$
> >
> > RewriteRule ^$ http://mypcname/perl.pl [L]
> >
> >
> >
> >
> >
> >
> >
> > To test on my local host but I am guessing that it is not even close to
> what
> > I want to do.
> >
> >
> >
> >
> >
> > The information in this email is confidential and may be legally
> privileged.
> > It is intended solely for the addressee. Access or use by any other
> person
> > to this internet email is not authorized and may be unlawful. If you are
> not
> > the intended recipient, please delete or destroy this email. If you do
> not
> > wish to receive future emails from this sender, please reply directly to
> > this email requesting you be removed from any mailing list.
>
> You want to redirect or rewrite ?
>
> --
> Nilesh Govindarajan
> Site & Server Administrator
> www.itech7.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
Posted by Nilesh Govindarajan <li...@itech7.com>.
On Thu, Mar 11, 2010 at 12:12 AM, Richard Schoenig
<Ri...@picis.com> wrote:
> I am new to using mod_rewrite and have been trying to create a rule to do
> something rather simple, but keep hitting a wall. I have been trying to
> research online how to do it, but I keep finding global changes and not
> specific to what I am trying to do. Essentially I am looking to use a
> rewrite rule to redirect users in an application from
>
>
>
> http://server4/perl.pl?n=1 to http://server1/perl.pl?n=1
>
>
>
>
>
> I tried using
>
> RewriteEngine on
>
> Options +FollowSymlinks
>
> RewriteCond %{QUERY_STRING} ^n=1$
>
> RewriteRule ^$ http://127.0.0.1/ perl.pl [L]
>
> RewriteCond %{QUERY_STRING} ^n=2$
>
> RewriteRule ^$ http://127.0.0.1/ perl.pl [L]
>
> RewriteCond %{QUERY_STRING} ^n=3$
>
> RewriteRule ^$ http://mypcname/perl.pl [L]
>
>
>
>
>
>
>
> To test on my local host but I am guessing that it is not even close to what
> I want to do.
>
>
>
>
>
> The information in this email is confidential and may be legally privileged.
> It is intended solely for the addressee. Access or use by any other person
> to this internet email is not authorized and may be unlawful. If you are not
> the intended recipient, please delete or destroy this email. If you do not
> wish to receive future emails from this sender, please reply directly to
> this email requesting you be removed from any mailing list.
You want to redirect or rewrite ?
--
Nilesh Govindarajan
Site & Server Administrator
www.itech7.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