1

I'm using mod_rewrite to map /foo/bar/baz to /foo/qux using

RewriteEngine on
RewriteBase /foo/
RewriteRule ^bar/baz$ bar/baz/ [L,R=permanent]
RewriteRule ^bar/baz/(.*) qux/$1 [L]

I want to allow indexes in /foo/qux, so I have Options +Indexes in /foo/qux/.htaccess.

The problem is that the index output reads "Index of /foo/qux" even when the URL used to access it is /foo/bar/baz. Ideally, I'd like the output to reflect the URL used (so either /foo/qux or /foo/bar/baz, depending). I'd settle for the output always saying "Index of /foo/bar/baz". Is there a way to do this using mod_rewrite or plain-vanilla Apache configuration options?

Chris Conway
  • 111
  • 3

2 Answers2

2

This isn't pure Apache configuration option, but as an alternative you could replace the Rewrites with symbolic links on the actual file system. With Linux, you would use:

ln -s <target> <link_name>
Kyle Brandt
  • 83,619
  • 74
  • 305
  • 448
  • This doesn't work: the whole point is to map baz in the component bar to another component qux that bar doesn't necessarily know about. I don't want any information about qux leaking into the bar hierarchy. – Chris Conway Jun 05 '09 at 17:42
  • I'm not quite sure what exactly what you mean with this comment other than the 'its not what I want' part... (It is Friday :-) ) The only other thing I recommend is that if you are already using mod_php you can find lots of generic directory listing code that will do the same thing that the Index directive does. I would think it would be pretty easy to alter the php to display the file listing based on the URL requested. Good luck, it is an interesting problem. I wouldn't be surprised if there is a pure apache answer. – Kyle Brandt Jun 05 '09 at 18:31
  • Sorry, I knew I wasn't being clear... I don't want explicit links from /foo/bar to /foo/qux because /foo/bar is being copied over from another project that has no need to know about the details of the filesystem layout on the web server. I want the web server configuration to handle it, rather than pushing those dependencies into the project. – Chris Conway Jun 05 '09 at 19:11
1

I don't believe it's possible, due to the order in which mod_rewrite and mod_autoindex handle the request. The path that mod_autoindex receives is and must be the "real" one.

Kyle's symlink workaround is the only solution I'm aware of.

Dan Carley
  • 25,617
  • 5
  • 53
  • 70