Mailing List Archive

mod_rewrite IP -> URL
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.

-Kyle

---------------------------------------------------------------------
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
RE: mod_rewrite IP -> URL [ In reply to ]
> From: Kyle [mailto:kyle@ccidomain.com]

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

This is a special case of the general problem discussed here:
http://httpd.apache.org/docs/misc/FAQ.html#canonical-hostnames

Feel free to write again if you have specific questions about the solutions.

Joshua.


---------------------------------------------------------------------
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
Re: mod_rewrite IP -> URL [ In reply to ]
Joshua,

I appreciate the reply, but that just puts me back where I started
(those are the two mod_rewrite pages I have been looking at).
Nonetheless, I have now successfully tried and gotten both <VirtualHost>
and Rewrite to work. Neither one solves my underlying (unmentioned)
problem. I'm going to try to get my head together on this and if I
can't find a solution, I'll start a new thread. Thanks.

-Kyle

Joshua Slive wrote:
>
> > From: Kyle [mailto:kyle@ccidomain.com]
>
> > 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?
>
> This is a special case of the general problem discussed here:
> http://httpd.apache.org/docs/misc/FAQ.html#canonical-hostnames
>
> Feel free to write again if you have specific questions about the solutions.
>
> Joshua.
>
> ---------------------------------------------------------------------
> 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

---------------------------------------------------------------------
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
Re: mod_rewrite IP -> URL [ In reply to ]
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.

The page Joshua referred you to does indeed contain the solution you are
looking for although it is rather cryptically presented...

Notice that the page (and your posting) concentrate on the use of
mod_rewrite. However, the actual solution lies in the use of "redirect".
These two functions are very similar but the essential difference is
that mod_rewrite is entirely server-side so that any re-writing of the
URL is invisible to the browser and the browser will not change. When
you do a redirect on the other hand, the server replies to the original
request with a 301 or 302 redirect response which causes the browser to
re-issue its request (to the new URL) *and* change its location window
contents. Consider the following example:

Re-write:
---------
<VirtualHost www.banana.com>
RewriteRule ^/(.*) http://www.kiwi.com/$1

User types in: http://www.banana.com/cherry.html
Server fetches: http://www.kiwi.com/cherry.html
Browser displays: http://www.banana.com/cherry.html

Redirect:
---------
<VirtualHost www.banana.com>
RedirectMatch (.*) http://www.kiwi.com/$1

User types in: http://www.banana.com/cherry.html
Server sends 301 -> http://www.kiwi.com/cherry.html
Browser requests: http://www.kiwi.com/cherry.html
User gets served: http://www.kiwi.com/cherry.html
Browser displays: http://www.kiwi.com/cherry.html

Read the docs on Redirect and RedirectMatch for the details...

Rgds,

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
Re: mod_rewrite IP -> URL: Read this first... [ In reply to ]
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