1

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.)

1 Answer 1

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]
1
  • Thanks. But where do I place these directives?
    – scrapdog
    Jan 26, 2011 at 17:30

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .