Google Answers Logo
View Question
 
Q: Apache Mod_rewrite rule needed ( No Answer,   3 Comments )
Question  
Subject: Apache Mod_rewrite rule needed
Category: Computers > Programming
Asked by: flight554-ga
List Price: $70.00
Posted: 01 Apr 2004 16:38 PST
Expires: 01 May 2004 17:38 PDT
Question ID: 323821
This a question on using mod_rewrite with the Apache webserver on
Linux. I want requests to one host to be served from an arbitrary
physical file path. I do not want to make any additions to the
httpd.conf file. This has to be done with mod_rewrite rules.

All requests to http://someplace.com currently lead to /physical/filepath1 .
I need to drop an .htaccess file at /physical/filepath1/.htaccess with
rewrite rules that will cause all requests for
http://someplace.com/whatever to be served from
/otherphysical/path/whatever WITHOUT changing the address bar in the
user's browser. The user will still think they are at
http://someplace.com/whatever

/otherphysical/path/ is on a completely different area of the
webserver's drive and there is no overlap between /otherphysical/path/
and /physical/filepath . Consider both physical drive locations to be
on different partitions. /otherphysical/path/ is not under the
DocumentRoot from http://someplace.com/

Clarification of Question by flight554-ga on 06 Apr 2004 11:53 PDT
The person writing the 2nd comment is correct. I have read the
mod_rewrite documentation and experimented with many rules for several
hours.

I need the URL to be silently rewritten so that the browser doesn't
know anything about the new address.

All the rules I have tried would work fine if the rewritten address
requests a file that is under the same DocumentRoot as the original
request. What I have not been able to do is rewrite the request to
serve a file from the same local disk that is outside the DocumentRoot
of the original request.

This sems like it cannot be done with an external request because the
browser will change the location in it's address bar.

I also cannot use mod_proxy to hide the 2nd external request because
we cannot install mod_proxy for other reasons.

Request for Question Clarification by snapanswer-ga on 06 Apr 2004 23:13 PDT
Don't quite give up yet.  There is another approach I am researching,
using other mod_rewrite commands.  However, I won't be able to give it
a solid test until the 9th or the 10th.  I could just post the idea,
but, I would like to test it.
Answer  
There is no answer at this time.

Comments  
Subject: Re: Apache Mod_rewrite rule needed
From: s3com-ga on 02 Apr 2004 03:45 PST
 
Hi!

You need  read about Apache  URL Rewriting.
http://httpd.apache.org/docs/misc/rewriteguide.html
Its copmlete guide to rewrite URLs with examples. 

On some webservers there are more than one URL for a resource. Usually
there are canonical URLs (which should be actually used and
distributed) and those which are just shortcuts, internal ones, etc.
Independent which URL the user supplied with the request he should
finally see the canonical one only.
Solution:
We do an external HTTP redirect for all non-canonical URLs to fix them
in the location view of the Browser and for all subsequent requests.
In the example ruleset below we replace /~user by the canonical
/u/user and fix a missing trailing slash for /u/user.

RewriteRule   ^/~([^/]+)/?(.*)    /u/$1/$2  [R]
RewriteRule   ^/([uge])/([^/]+)$  /$1/$2/   [R]
Canonical Hostnames
Description:
...
Solution:

RewriteCond %{HTTP_HOST}   !^fully\.qualified\.domain\.name [NC]
RewriteCond %{HTTP_HOST}   !^$
RewriteCond %{SERVER_PORT} !^80$
RewriteRule ^/(.*)        
http://fully.qualified.domain.name:%{SERVER_PORT}/$1 [L,R]
RewriteCond %{HTTP_HOST}   !^fully\.qualified\.domain\.name [NC]
RewriteCond %{HTTP_HOST}   !^$
RewriteRule ^/(.*)         http://fully.qualified.domain.name/$1 [L,R]

Regards.
Subject: Re: Apache Mod_rewrite rule needed
From: snapanswer-ga on 02 Apr 2004 18:07 PST
 
I looked at this example, however, flight554 does not want the address
to update in the browser.  I think the example in the comment says it
will be an external redirect and update the address.

I tested some approaches, but, could not get the desired result.  If I
am not mistaken, if you rewrite to an external link (a link beginning
with http:// for example) it will redirect and appear in the browser. 
At least, that's what I am coming up with.  I will keep trying.
Subject: Re: Apache Mod_rewrite rule needed
From: jdps-ga on 07 Apr 2004 10:40 PDT
 
Your question isn't very clear.  From a literal interpretation, you can
accomplish what you want by simply changing the DocumentRoot to point to
/otherphysical/path

But, in general, you can use mod_rewrite to map paths without letting
the browser know.  For example,
RewriteRule ^/foo(.*) /full/path/to/bar/$1
will do this (note no [R] on the end!)
as will a simple
Alias /foo /full/path/to/bar
Of course, the second one can't be used in .htaccess, and the first one
may need to be adjusted for use in .htaccess.  Generally, it is much simpler
to use rewrite stuff in httpd.conf if you can.

Also remember that you'll need to assure that /otherphysicial/path has both
unix and apache permissions allowing access to the server.

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy