Forum Moderators: phranque

Message Too Old, No Replies

Is This Possible with mod rewrite?

legally replacing IP address (numbers) with domain name

         

diddly

8:15 pm on Jun 27, 2015 (gmt 0)

10+ Year Member



I am member of an organization that provides a web address redirection service to its members in the shape of
"organization.country/myusername/"
i can set this up to redirect to my servers IP address (it does not have a DNS name). this works, but the address in the url bar then changes to a naked and ugly IP address.

Now on my debian server, is it possible to tell apache to replace the nn.nn.nn.nn IP address with "organization.country/myusername/", so that it looks better to the visitor?

i think it would be a straightforward search-and-replace, but i don't know if it's technically possible to change the root of the url in this way without affecting the internal structure of my website.
tbh, apache's documentation makes my head swim. i'm totally new to this.

hopefully i'm making sense, i probably didn't get all the terms right.
thanks.

lucy24

11:35 pm on Jun 27, 2015 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



The exact wording of your question was "Is this possible with mod_rewrite?" No, it isn't. You might be able to achieve it using mod_alias and/or mod_proxy. (The "and/or" means that you may need to talk to someone who speaks Apache. I just do Regular Expressions, with particular reference to mod_rewrite.)

You need to get a firm grip on the difference between a redirect and a rewrite.

In a redirect, you're sending a message back to the browser, instructing them to make a fresh request at such-and-such new URL, which might be on the same host or an entirely different one, the same server or on the other side of the planet. The human user doesn't need to take any further action-- but their browser does, and this new action is reflected in the address bar, showing where the browser "thinks" it is.

In a rewrite, you accept the user's request, and then secretly go and serve content from some other location. As long as the new location is under the same hostname and the same (physical) directory on the server, this is exceedingly easy with mod_rewrite. But once you're talking about a change in hostname, or using a directory other than the one the original DNS points to, you're a little beyond the realm of mod_rewrite unaided.

:: wandering off to refresh memory on difference between [P] and [PT] which I've got a long-standing mental block about ::

diddly

8:01 am on Jun 28, 2015 (gmt 0)

10+ Year Member



ok thanks.

to clarify:
i have no influence on what is happening on "organization.country/myusername/" - i can only tell it where to redirect to.
once the client arrives at that new destination (whether it's a "naked" ip address or some domain name) i just want the url to look like they're still on "organization.country/myusername/". afaiu, that's not a redirect, not even on the same server. it's just cosmetics.

i had come across mod_alias, too, but i'm still very, very green about all things server.
i don't even know how to phrase this problem properly to be able to search for it...

bird

12:39 pm on Jun 28, 2015 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



As long as your own server does not have www.domain.tld pointing to it, then the browser will not show that in the address bar. There's nothing you can do in mod_rewrite to "fake" a DNS entry.

lucy24

5:07 pm on Jun 28, 2015 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



i just want the url to look like they're still on "organization.country/myusername/". afaiu, that's not a redirect, not even on the same server. it's just cosmetics

If you want the URL to say suchandsuch, then the DNS for suchandsuch must point to the physical directory where site suchandsuch is stored. It doesn't sound as if this is under your control.

diddly

9:31 pm on Jun 29, 2015 (gmt 0)

10+ Year Member



my server has "organization.country/myusername/" pointing to it.
so in a way that is my dns entry, afaiu. i'm not trying to fake anything.
i just had a look on the organization's admin panel, it says something about DNS-alias, DNSKEY and DNSSEC.
translated, it says: "Get DNSKEY records from member's DNS server...: DS records: No DNSKEY records."
Not sure what this means or if this is final or if it even has a bearing on my plan.

bird

10:30 pm on Jun 29, 2015 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



That DNS entry points to "organisation"s server, not to yours. This is made obvious by the fact that, when "organisation" redirects visitors to you, they end up seeing your IP in the address bar.
A DNS entry can't point to two different servers in that way, and it does not address subdirectories.
A possible workaround might be to have a similar but different DNS entry, eg. by using subdomains.
Then "organisation.country/myusername" would redirect to "myusername.organisation.country/", which points to your own server. Of course I have no idea if "organisation" supports this. The other question is why you would want to still have the first address form if the second was available.

diddly

6:28 am on Jul 1, 2015 (gmt 0)

10+ Year Member



thanks, bird.
i just wanted to make 100% sure you understood my question before trusting your answer.
since my knowledge is more than limited in this area, i'll happily take your word with all 10+ years of experience backing it.