cancel
Showing results for 
Search instead for 
Did you mean: 

RESTful services (cgi,php) and mod_rewrite

badbetty
Grafter
Posts: 31
Registered: ‎25-09-2008

RESTful services (cgi,php) and mod_rewrite

Hello to all !
I have spent some time reading the forum and researching articles relating to mod_rewrite, .htaccess etc. I am a little clearer about how to use these 2 'functions' and in relation to Plusnet webspace, but I need some help just pulling it all together to clarify if the subject of this post/topic is possible.
Motivation:
I want to be able to present RESTful/user friendly URLs to access website file/pages and to any scripts that dynamically generate pages, whilst keeping a consistent url domain (i.e. no redirects). I hope that makes sense  Crazy

Observations:
re: default plusnet web space(s):  www.username.plus.com ; and  ccgi.username.plus.com
I have sorted (i think) being able process user friendly url's, via mod_rewrite, so that the physical file in the same webspace is returned and the domain url is consistent (for want of a better phrase).
e.g.  www.username.plus.com/docs/0001 ; rewritten to    www.username.plus.com/documents/physicaldoc1.html produces the output without affecting the url  ie. it remains consistent.
However, I cannot do this if I am 'rewriting' to the ccgi webspace to dynamically process a user friendly url via a script without  a redirect happening and the domain url keeping consistent.
e.g. www.username.plus.com/docs/0001 ;   rewritten to    ccgi.username.plus.com/cgi-bin/getdoc.php?id=0001
If possible I would like to keep the site based on the www.username.plus.com web space, but I am wondering if the only way is to port it all to the ccgi server....... which is not recommended.
As an aside,  I could include using a script e.g. php  to act as a controller/despactcher for  processing all user-friendly url's dynamically, IF it is possible to stop the apparent domain redirects.

I hope this is written well enough to understand.  Please if any one has any suggestions for solutions, do reply. Or if I have been remiss then let me know how and what I need to do to put it right.

Thank you
Chris
3 REPLIES 3
Gabe
Community Veteran
Posts: 767
Registered: ‎29-10-2008

Re: RESTful services (cgi,php) and mod_rewrite

Hi Chris,
No, if I interpret you correctly then you're right, you can't fake the domain with a rewrite. If you were prepared to filter out older browsers and give them a less friendly alternative, then you could use CORS and AJAX the content off ccgi, but I think it would be easier just to move your site onto ccgi and repoint the domain.
Gabe
badbetty
Grafter
Posts: 31
Registered: ‎25-09-2008

Re: RESTful services (cgi,php) and mod_rewrite

Thanks for the clarification Gabe; it is as I thought then  Undecided
I can guess at some reasons why the webspace servers were set up this way, but it is disappointing none the less - as its such a 'small' step to open up some nice possibilities (for me anyway).

Thanks again.
Chris
Ben_Brown
Grafter
Posts: 2,839
Registered: ‎13-06-2007

Re: RESTful services (cgi,php) and mod_rewrite

It's not to do with the way the webserver is set up, it's how mod_rewrite works.
mod_rewrite can only keep the URL the same if it can fetch the file it needs to fulfil the request from it's own storage. An url on another server is not in it's storage, so it can't get the data it needs to send back to the client, and as a result it redirects the client to that resource instead.
From http://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewriterule:
Quote
If an absolute URL is specified, mod_rewrite checks to see whether the hostname matches the current host. If it does, the scheme and hostname are stripped out and the resulting path is treated as a URL-path. Otherwise, an external redirect is performed for the given URL.

To be able to present data from another server and preserve the URL you'd need to use something like mod_proxy, which on a shared platform is just too risky to enable.