Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

How can I configure Apache to direct requests for particular URL on server to a particular directory, while at the same time transforming how that URL is seen by the script that processes it?

Say I have a php script in the following directory:

/somedir/foo/script.php

I would like all incoming HTTP requests to http://server/foo/* to be processed by /somedir/foo/script.php. However, I would also like the script to know what the remainder of the URI is in the REQUEST_URI variable.
(The * part of the URL is opaque information that is only meaningful to the script, and could be anything)

For example:

http://example.com/foo/

will be handled by /somedir/foo/script.php, and the script will see the REQUEST_URI as simply "/" and

http://example.com/foo/the/quick/brown/fox.html

will also be handled by /somedir/foo/script.php, while REQUEST_URI will be seen as "/the/quick/brown/fox.html"

How do I configure Apache to behave this way?

(Note that this is strictly an Apache question; I do not want to alter the script in any way.)

share|improve this question

1 Answer 1

This is fairly easily done with mod_rewrite, Wordpress uses this quite often

RewriteBase /foo/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /somedir/foo/script.php [L]
share|improve this answer
    
Thanks. But where do I place these directives? –  scrapdog Jan 26 '11 at 17:30

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.