Welcome to MobyThreads.com!
FAQFAQ      ProfileProfile    Private MessagesPrivate Messages   Log inLog in
All support for the MobyThreads Threaded phpBB MOD can now be found on welsolutions at this forum

RewriteCond on IP and endless loops

 
   Web Hosting and Web Master Forums (Home) -> Apache RSS
Next:  Confused about virtual hosts and namve vs IP host..  
Author Message
nospam70

External


Since: Jun 07, 2004
Posts: 5



(Msg. 1) Posted: Mon Jun 07, 2004 11:17 pm
Post subject: RewriteCond on IP and endless loops
Archived from groups: alt>apache>configuration (more info?)

Hope this is not OT for this group.

I'm not sure if there is some server side setting holding me back here.
Would appreciate some help after 8 hours of trying:-/

Does anyone know why this in .htaccess:

a) won't work and throws the server into an endless loop

Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REMOTE_ADDR} ^111\.111\.111\.111$ [OR]
RewriteCond %{REMOTE_ADDR} ^222\.111\.111.111$
RewriteRule .* "http://www.site.com/go-here.htm" [L]

b) and this *seems* to stall the server (in cgi mode if that helps at all)

Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_URL} !/"http://www.site.com/go-here.htm"
RewriteCond %{REMOTE_ADDR} ^111\.111\.111\.111$ [OR]
RewriteCond %{REMOTE_ADDR} ^222\.111\.111.111$
RewriteRule .* "http://www.site.com/go-here.htm" [L]


I just want to redirect some ip's to a specific page. What am I missing?


--
Tony

 >> Stay informed about: RewriteCond on IP and endless loops 
Back to top
Login to vote
purlgurl

External


Since: Oct 24, 2003
Posts: 127



(Msg. 2) Posted: Mon Jun 07, 2004 11:17 pm
Post subject: Re: RewriteCond on IP and endless loops [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Tony wrote:

(snipped)

 > Does anyone know why this in .htaccess:

 > a) won't work and throws the server into an endless loop

 > RewriteEngine On
 > RewriteCond %{REMOTE_ADDR} ^111\.111\.111\.111$ [OR]
 > RewriteCond %{REMOTE_ADDR} ^222\.111\.111.111$
 > RewriteRule .* "http://www.site.com/go-here.htm" [L]

You are sending your client right back to your htaccess file,
which redirects back to your htaccess, which redirects back
to your htaccess, which redirects...

Move your go-here.htm to a parallel tree or above your
htaccess directory. Remove "go-here" from your current
htaccess directory / child directory tree.

An alternative,

RewriteCond %{REQUEST_URI} !^.*go-here.*$
RewriteCond %{REMOTE_ADDR} ^111\.111\.111\.111$ [OR]
RewriteCond %{REMOTE_ADDR} ^222\.111\.111.111$
RewriteRule .* "http://www.site.com/go-here.htm" [L]

requested file ! (not) match "go-here" continue process
else quit

if true, continue to next condition / rule
if false, quit

For that case example, your initial htaccess redirect
will create a new url with your go-here, allowing passage,
having returned a false value for the first condition on
the redirect return to the same directory.

Research and read about REGEX matching; there are a lot of
shortcut methods. My example is verbose for clarity.


 > b) and this *seems* to stall the server (in cgi mode if that helps at all)

 > RewriteCond %{REQUEST_URL} !/"http://www.site.com/go-here.htm"

^

REQUEST_URI

It is a capital "I" (eye) not an "L" (ell).


Purl Gurl
--
Learn To Speak, Read And Write Choctaw!
<a style='text-decoration: underline;' href="http://www.purlgurl.net/~choctaw/" target="_blank">http://www.purlgurl.net/~choctaw/</a><!-- ~MESSAGE_AFTER~ -->

 >> Stay informed about: RewriteCond on IP and endless loops 
Back to top
Login to vote
hans1

External


Since: Mar 29, 2004
Posts: 672



(Msg. 3) Posted: Tue Jun 08, 2004 12:38 am
Post subject: Re: RewriteCond on IP and endless loops [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

"Tony" <nospam RemoveThis @nospam.net> schreef in bericht
news:914xc.115$e%5.93@newsfe2-gui.server.ntli.net...
 > Does anyone know why this in .htaccess:
 > a) won't work and throws the server into an endless loop
 > Options +FollowSymLinks
 > RewriteEngine On
 > RewriteCond %{REMOTE_ADDR} ^111\.111\.111\.111$ [OR]
 > RewriteCond %{REMOTE_ADDR} ^222\.111\.111.111$
 > RewriteRule .* "http://www.site.com/go-here.htm" [L]
 >
 > b) and this *seems* to stall the server (in cgi mode if that helps at all)
 > Options +FollowSymLinks
 > RewriteEngine On
 > RewriteCond %{REQUEST_URL} !/"http://www.site.com/go-here.htm"
Assuming that first slash is just a type _here_ ...

 > RewriteCond %{REMOTE_ADDR} ^111\.111\.111\.111$ [OR]
 > RewriteCond %{REMOTE_ADDR} ^222\.111\.111.111$
 > RewriteRule .* "http://www.site.com/go-here.htm" [L]

Change your rules to
RewriteCond %{HTTP_REQUEST} ^some-folder/
RewriteRule .* go-here.htm [L]
might keep Apache from sending a HTTP-redirect, making it directly send the
content of the 'redirected' page.
Added a condition to keep those clients containt in their 'private' folder
too.


HansH
..<!-- ~MESSAGE_AFTER~ -->
 >> Stay informed about: RewriteCond on IP and endless loops 
Back to top
Login to vote
nospam70

External


Since: Jun 07, 2004
Posts: 5



(Msg. 4) Posted: Tue Jun 08, 2004 12:38 am
Post subject: Re: RewriteCond on IP and endless loops [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

HansH wrote:

<snipped>

:: RewriteCond %{REQUEST_URL} !/"http://www.site.com/go-here.htm"
: Assuming that first slash is just a type _here_ ...


Hi Hans - thanks for the reply. That wasn't a typo. I read an example
somewhere on google that the / was needed.


:: RewriteCond %{REMOTE_ADDR} ^111\.111\.111\.111$ [OR]
:: RewriteCond %{REMOTE_ADDR} ^222\.111\.111.111$
:: RewriteRule .* "http://www.site.com/go-here.htm" [L]
:
: Change your rules to
: RewriteCond %{HTTP_REQUEST} ^some-folder/
: RewriteRule .* go-here.htm [L]
: might keep Apache from sending a HTTP-redirect, making it directly
: send the content of the 'redirected' page.
: Added a condition to keep those clients containt in their 'private'
: folder too.


But I also read somewhere that if I use HTTP_REQUEST, it can be easily
spoofed ??
That's why I was chasing a specific IP solution with REMOTE_ADDR
Please correct me if I'm barking up the wrong tree. It's been a long few
days ...

Have I got this wrong? Is there not a way to do this:

RewriteCond %{REMOTE_ADDR} ^111\.111\.111.111$
RewriteRule .* "http://www.site.com/go-here.htm" [L]



Thanks

--
Tony
 >> Stay informed about: RewriteCond on IP and endless loops 
Back to top
Login to vote
purlgurl

External


Since: Oct 24, 2003
Posts: 127



(Msg. 5) Posted: Tue Jun 08, 2004 12:38 am
Post subject: Re: RewriteCond on IP and endless loops [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Tony wrote:

 > HansH wrote:

(snipped)

 > :: RewriteCond %{REQUEST_URL} !/"http://www.site.com/go-here.htm"
 > : Assuming that first slash is just a type _here_ ...

 > That wasn't a typo. I read an example
 > somewhere on google that the / was needed.

Use of / before a file name indicates it is found in
your www document root directory, such as your htdocs
directory installed by default.

/go-here.htm

That is the same as,

<a style='text-decoration: underline;' href="http://www.site.com/htdocs/go-here.htm" target="_blank">http://www.site.com/htdocs/go-here.htm</a>

However, Apache doesn't need the htdocs path
because / is an "alias" for that directory.

/go-here.htm

<a style='text-decoration: underline;' href="http://www.site.com/go-here.htm" target="_blank">http://www.site.com/go-here.htm</a>


Those two immediately above, are the same request path.

Note there is a distinct difference between your
"server root" directory and your "document root"
directory, noted in your httpd.conf file.

Typically, use of / should _not_ be followed by
a http reference; that is already included by
automagic default.


Purl Gurl<!-- ~MESSAGE_AFTER~ -->
 >> Stay informed about: RewriteCond on IP and endless loops 
Back to top
Login to vote
purlgurl

External


Since: Oct 24, 2003
Posts: 127



(Msg. 6) Posted: Tue Jun 08, 2004 12:38 am
Post subject: Re: RewriteCond on IP and endless loops [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Purl Gurl wrote:

 > Tony wrote:
  > > HansH wrote:

(snipped)

  > > :: RewriteCond %{REQUEST_URL} !/"http://www.site.com/go-here.htm"
  > > : Assuming that first slash is just a type _here_ ...

  > > That wasn't a typo. I read an example
  > > somewhere on google that the / was needed.

 > /go-here.htm

<font color=purple> > <a style='text-decoration: underline;' href="http://www.site.com/go-here.htm</font" target="_blank">http://www.site.com/go-here.htm</font</a>>

 > Those two immediately above, are the same request path.

 > Typically, use of / should _not_ be followed by
 > a http reference; that is already included by
 > automagic default.

I need to qualify this. Be careful to not allow me
to confuse you on "document root" and "relative path"
syntax. Research and read about use of alias / syntax
and use of /child/directory/file.html as a relative
path syntax.

This is why I often suggest to readers to always use
a full path, never use a relative path. Doing so adds
great clarity and avoids confusion which is displayed
in my previous article by not qualifying completely.

There is another problem. If your machine, upon which
you are browsing the net, if your machine has Apache
running as a "localhost" system, relative paths in
html documents on the net, actually reference your
running localhost Apache resulting in 404 not found
errors popping up. This is severe problem when style
sheets (css) are used.

Use full paths, always, both internally to Apache
and in your webpages.


Purl Gurl<!-- ~MESSAGE_AFTER~ -->
 >> Stay informed about: RewriteCond on IP and endless loops 
Back to top
Login to vote
hans1

External


Since: Mar 29, 2004
Posts: 672



(Msg. 7) Posted: Tue Jun 08, 2004 2:38 am
Post subject: Re: RewriteCond on IP and endless loops [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

"Tony" <nospam.DeleteThis@nospam.net> schreef in bericht
news:B65xc.125$e%5.87@newsfe2-gui.server.ntli.net...
 > :: RewriteCond %{REQUEST_URL} !/"http://www.site.com/go-here.htm"
 > : Assuming that first slash is just a type _here_ ...
 > Hi Hans - thanks for the reply. That wasn't a typo. I read an example
 > somewhere on google that the / was needed.
AFAIK quite unlikely either _out-side_ a quoted string or _upfront_ a
protocol or even upfront a path _in_.htaccess_ .

 > :: RewriteCond %{REMOTE_ADDR} ^111\.111\.111\.111$ [OR]
 > :: RewriteCond %{REMOTE_ADDR} ^222\.111\.111.111$
 > :: RewriteRule .* "http://www.site.com/go-here.htm" [L]
 > : Change your rules to
 > : RewriteCond %{HTTP_REQUEST} ^some-folder/
 > : RewriteRule .* go-here.htm [L]
 > : might keep Apache from sending a HTTP-redirect, making it directly
 > : send the content of the 'redirected' page.
 > : Added a condition to keep those clients containt in their 'private'
 > : folder too.
 > But I also read somewhere that if I use HTTP_REQUEST, it can be easily
 > spoofed ??
Oops ... HTTP_REQUEST should be REQUEST_URI
Multiple URLencoding -%xx- combined with some . -current folder- and
... -parent folder- elements in path do have a worriing reputation on some
platforms. However, REMOTE_ADDR _can_ be spoofed too.

 > That's why I was chasing a specific IP solution with REMOTE_ADDR
Infact it was not my intention to _remove_ those conditions on remote
address ... only suggesting to change the _rule_ not its
_conditions_ -though, could have been more carefully expressing-.

 > Have I got this wrong? Is there not a way to do this:
 > RewriteCond %{REMOTE_ADDR} ^111\.111\.111.111$
 > RewriteRule .* "http://www.site.com/go-here.htm" [L]
As any request is redirected to the same single page, you end up serving
only _that_ page.
If that _single_ page fits your needs, don't make (only) some-folder
available to them.

HansH<!-- ~MESSAGE_AFTER~ -->
 >> Stay informed about: RewriteCond on IP and endless loops 
Back to top
Login to vote
Display posts from previous:   
Related Topics:
rewrite loops - I got a ssl-proxy that works fine with this rule set. lockfile is also defined. RewriteEngine on #RewriteLog /dev/null #RewriteLog 0 RewriteLog /var/log/apache/sslproxy.log RewriteLogLevel 1 RewriteMap lowercase int:tolower ..
   Web Hosting and Web Master Forums (Home) -> Apache All times are: Pacific Time (US & Canada) (change)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]