Forum Moderators: phranque

Message Too Old, No Replies

mod rewrite help

         

bojomojo

10:19 am on Dec 7, 2008 (gmt 0)

10+ Year Member



Can I use mod_rewrite to rewrite local urls to external ones.

The thing is i want to display my helpdesk to my resellers on thier websites while offer the support.

Basically is it possible for mod rewrite to do the external rewriting?

for example:
when the user clicks on support.domain.com
it goes to domain2.com/support

is it possible? and how

g1smd

5:12 pm on Dec 7, 2008 (gmt 0)

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



Do you want a redirect or a rewrite?

Be clear as to what the differences are.

bojomojo

4:51 pm on Dec 8, 2008 (gmt 0)

10+ Year Member



i need a rewrite

jdMorgan

3:33 pm on Dec 9, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



For information on rewriting subdomains to subdirectories, try a search on WebmasterWorld for "RewriteCond HTTP_HOST RewriteRule subdomain subdirectory" and similar words to find dozens of threads on this subject...

The problem of passing a request to an external server is a different problem. If you have control of the subdomains like support.domain.com, then you can reverse-proxy these requests to domain2.com/support. If not, you will need those sites to link from <domain>.com to (perhaps) support.<domain>.domain2.com.

This is not as good at preserving 'branding' as what you want, but it may be the best you can achieve without having some control of your clients' servers.

Jim

bojomojo

3:38 pm on Dec 9, 2008 (gmt 0)

10+ Year Member



I own all the servers the domains are on and have control over all accounts,
I need to redirect the user to a domain while the address in the address bar is the same, i know i need mod proxy, but how can this be done?

jdMorgan

5:25 pm on Dec 9, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Don't confuse a redirect with a proxy through-put. They are not at all the same thing.

A redirect sends a server response to the client saying, "Please re-request what you asked for using this new URL." If the client does issue a new request in response to that redirect, then it will show the new URL in its address bar. This is a browser function, and beyond your control.

So obviously, you don't want a redirect, you want a proxy through-put, where your server simply forwards the client request to another server "behind the scenes" and the client is unaware of this happening.

Setting up a reverse proxy is not a trivial task. For example, you will need to configure the front-end server to pass client request header information to the back-end server, and configure the back-end server to log this client header information in addition to or instead of the headers coming from the front-end server. Otherwise, the back-end server will log all requests as coming from the front-end server, and therefore its logs will contain no information about the original client requests. At a minimum, you will probably want the front-end server to send the client's REMOTE_ADDR to the back end using an X_FORWARDED_FOR header, so that the back-end server can log the proper IP address of the client.

Because this is a complex task, please understand that we cannot provide the level of support you may need to get it working; We have a limited number of all-volunteer contributors and staff here, most of whom have their own jobs to look after. So it'll be down to you to learn what you need to learn, or to hire the job out to a (preferably-local) contractor. We can handle very-specific questions here, but not "write my code"- or "configure my server(s)"- type requests.

See Apache mod_proxy and mod_rewrite for more information. Our Forum Charter [webmasterworld.com] may be quite helpful to you, both in learning how to get the most from this forum, and because it contains links to useful resources.

Jim

bojomojo

10:30 am on Dec 11, 2008 (gmt 0)

10+ Year Member



I have the code now, but its not functioning properly
What is does successfully:
When i go to www.domain2.com/support it shows me desk.domain1.com
but then all links in that page point to domain2.com/file.php not domain2.com/support/file.php

here is the code:

ProxyRequests Off

<Proxy *>
Order deny,allow
Allow from all
</Proxy>

ProxyPass /support [desk.domain1.com...]
ProxyPassReverse /support [desk.domain1.com...]

jdMorgan

1:28 pm on Dec 11, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Good! That means that the proxy function worked, and you have only a relatively-minor clean-up to do regarding the interaction of your rewrite rules with mod proxy. Or perhaps your on-page links need to be modified; They may need to be in server-relative form, as in <a href="/support/file.php">, along with a rewrite on /domain1.com to send requests for proxied URL /support/xyx to the filepath /xyz, and a change to the proxy directives:
ProxyPass /support http://desk.domain1.com/support
ProxyPassReverse /support http://desk.domain1.com/support

The idea is to get all of the "filepaths" in agreement on your support pages and in the proxy directives on the "customer" servers, and then take a few steps (e.g mod_rewrite) to 'steer' those filepaths to the proper location in your support server.

Remember, it is the browser that resolves relative links on your pages into the canonical URLs that it will request from your server(s), according to the domain and "directory" that it "sees" in its address bar. Look at the links on your proxied pages using view-page-source in the browser and examine the HTTP transactions between your server(s) and the browser using the Live HTTP Headers add-on for Firefox/Mozilla browsers. This may prove quite helpful in figuring all of this out.

Jim

bojomojo

1:40 pm on Dec 11, 2008 (gmt 0)

10+ Year Member



the problem is i cant edit the relative links, they are automatically generated, i think using support.domain2.com in stead of /support/ can solve it, the problem is i dont know how to make that happen :)

jdMorgan

3:04 pm on Dec 11, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



In either case, the simplest answer is to edit the script that produces the links on the customers' pages, modifying the code to generate the links that you want.

I'm sorry I have to answer in generalities; You're dealing with a complex problem with many variables and dependencies, and solutions to these problems are "highly-customized," making specific answers impossible in a limited-information forum context.

Jim