You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Owen Boyle <ob...@bourse.ch> on 2001/12/18 10:31:26 UTC

Re: mod_rewrite IP -> URL: Read this first...

Kyle wrote:
> 
> I'm pulling my hair out here, and I don't have much left.  Can anyone
> send me an example of how to change an IP to a URL on the user's
> browser?  In other words, user types in this:
> 
> http://XXX.XXX.XXX.XXX/whatver
> 
> and mod_rewrite does it's magic and the user's browser displays this in
> the address bar:
> 
> http://www.mydomain.com/whatever
> 
> Can mod_rewrite do this?  If so, I've been RTFMing all afternoon and I
> just don't see how to do it.  Any guidance would be greatly appreciated.
> 
> I wish someone would write a new doc called, "mod_rewrite for
> dumbasses".  MAYBE then I'd get it.

Hang on a minute. The other response I sent concentrates on solving your
problem without any regard to the technique used. In it, I recommend
that you *don't* use mod_rewrite but that you use Redirect instead. My
thinking was that your problem is so simple that mod_rewrite is a bit of
an overkill when a simple Redirect can do the job in one line with no
extra modules.

Having written that, it occurs to me that you might *want* to use
mod_rewrite and might think my post implies that mod_rewrite cannot be
used for the purpose of redirection. This is not exactly true and, in
fact, mod_rewrite can be used for practically anything. So if you want
to use mod_rewrite, go right ahead!

This time, the secret lies in the use of the "R" flag to the rewrite
rule - this flag forces the server to generate a "302 - moved
permanently" message which causes the browser to re-issue the request
and thus change its location window contents. e.g.

<VirtualHost XXX.XXX.XXX.XXX>
RewriteRule  ^/(.*)  http://www.mydomain.com/$1 [R]

Sorry for the confusion!

Owen Boyle.

---------------------------------------------------------------------
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
For additional commands, e-mail: users-help@httpd.apache.org