Forum Moderators: phranque

Message Too Old, No Replies

URL Manipulation

how to show a different URL

         

rhjohnsonsc2

3:45 pm on Jul 31, 2012 (gmt 0)

10+ Year Member



My Site is http://example.com each club that joins will be placed in a sub-directory with their "Club Name" (e.g. http://example.com/SomeClub)

In each clubs directory will be 3 Web Based Applications for our system:
1. event-check-in
2. member-add
3. member-signup

The member-signup directory is a Web Application Form a clubs potential members to fill out to become a member of the night club. I do not want to add this form onto the clients (Club Owners server), I have to protect my source code.

My question is:

Can I somehow have an .htaccess file in either the clubs directory (SomeClub) or inside of the member-signup directory that will rewrite the URL in the address bar to look like it is still on the Club's website server?

(e.g. http://example.com/SomeClub/member-signup rewritten to look like http://example.com/join)

basically, if I host the Web Form on my server in a sub-directory for the club, I want the address bar to look like the Web Form is on the actual club's website.

g1smd

9:07 pm on Jul 31, 2012 (gmt 0)

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



Mod_rewrite does not "make URLs look like" anything.

It works exactly backwards to how you think it does.

Link to the URL that you want the user to "see" and "use". Mod_rewrite kicks in after that link is clicked.

Mod_rewrite rewrites the request to fetch the content from some other specific location within the server.

rhjohnsonsc2

9:25 pm on Jul 31, 2012 (gmt 0)

10+ Year Member



Ok, but that still did not answer my question. Let me see if I can be a little more clear.

Lets say my client's club website is mynightclub.com and we have his/her web person add a menu item for the web application form but does not upload anything but redirects the menu item "Join" to a URL on my server http://example.com/mynightclub/member-signup

So instead of the potential members of the club seeing http://example.com/mynightclub/member-signup but see a different URL in the address bar like mynightclub.com/join

Can this be done with .htaccess? If so, can someone show me how and where to place the .htaccess file at.

lucy24

11:15 pm on Jul 31, 2012 (gmt 0)

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



I think you misunderstood the answer. Only a redirect can change the visible URL. A rewrite can then step in and fetch content from anywhere you like.

In your case, you don't need a redirect. That's only for visitors from outside requesting the wrong URL. You need to write your code so it displays http://example.com/mynightclub/member-signup in the first place. And then use htaccess to rewrite to http://example.com/mynightclub/member-signup.

It isn't clear whether "mynightclub.com" is a separate domain for each member (this seems impossible), or a subdomain "mynightclub.example.com" or a top-level directory "www.example.com/mynightclub".

rhjohnsonsc2

11:37 pm on Jul 31, 2012 (gmt 0)

10+ Year Member



Ok. Are you saying that I would need to place a .htaccess file on the client's server in mynightclub.com/join ?

A little more advice and instruction would be greatly appreciated.

phranque

1:52 am on Aug 1, 2012 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



what you want is mod_proxy:
http://httpd.apache.org/docs/current/mod/mod_proxy.html [httpd.apache.org]

the webmaster links to mynightclub.com/join and the mynightclub.com server sends the request for /join to example.com/mynightclub/member-signup using mod_proxy directives.

exotic

3:23 am on Aug 1, 2012 (gmt 0)

10+ Year Member



Using mod_proxy requires that it is installed on the club owner's server.

What about using an iframe?

lucy24

9:44 am on Aug 1, 2012 (gmt 0)

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



Urk. Too much cut-and-paste. When I wrote
You need to write your code so it displays http://example.com/mynightclub/member-signup in the first place. And then use htaccess to rewrite to http://example.com/mynightclub/member-signup.

I of course meant
You need to write your code so it displays http://example.com/mynightclub/member-signup in the first place. And then use htaccess to rewrite to http://example.com/join.


Sorry. Ouch. That is:

Write your html so it says

www.example.com/{url you want the user to see}

And then rewrite in htaccess to

www.example.com/ {file where the activity really takes place}

The location of an htaccess file is based on the real filepath, not the displayed url. So you have to put it where it will be "seen" by the requests you need to rewrite. Ordinarily this would be at the root level. If it's your own server, you don't need htaccess at all. Put it in the config file.

But you're missing one piece. The rewritten request has to "remember" where it belongs, so you will almost certainly need a parameter. The basic structure is something like

RewriteRule ^(myclubname)/signup /join.php?club=$1 [L]

And then your join.php page uses the "myclubname" value to do all the stuff that's specific to this club. Not just the nitty-gritty of signing up, but also the html things like pulling up the appropriate stylesheet and setting the page title to make it look as if you're in the /myclubname/ directory.

g1smd

10:37 am on Aug 1, 2012 (gmt 0)

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



The location of an htaccess file is based on the real filepath, not the displayed url.

At the server level, the location of the htaccess file should be based on the requested hostname, the one shown in the link the user clicked on, this htaccess file usually being located in the root folder of wherever the requested hostname resolves to.

If the request needs to fetch information from some other hostname, but you don't want the user to know what that other hostname is, then you proxy the request from the originally requested hostname to the hostname where the content really resides.

So, the action is exactly backwards to the OPs original description.

rhjohnsonsc2

12:56 pm on Aug 1, 2012 (gmt 0)

10+ Year Member



Thanks for the replies lucy24 & g1smd.

I wonder if exotic is on to something better. Would you recommend an iframe to this instead, or rely on .htaccess?