Automatic path (not URL) rewriting with apache?
I'm not sure if this is at all possible, but I would like to automatically rewrite a path whenever a page is requested (through apache). I don't want to actually rewrite the URL, but the absolute path the page is retrieved from.
Let me try to explain that more clearly. I have a directory on my Linux server, say /var/www which serves as the document root for Apache. So when someone requests http://www.mydomain.com/somepage.html, it serves /var/www/somepage.html. But what I want is that when someone requests http://www.mydomain.com/concepts/clientA/somepage.html, instead of serving /var/www/concepts/clientA/somepage.html, it serves /home/concepts/clientA/somepages.html. So as soon as the root directory in the url is "concepts", I want it to retrieve the page from the /home/concepts directory. /homes/concepts/clientA/somepage.html is not directly accessible from the web so I can't use mod-rewrite. Also, I don't want to create symbolic links for each client because I simply want to create subdirs under the "concepts" directory, and be able to automatically access them over the web. Hope my question makes any sense. |
Sorry, my question above is incomplete (since the easy solution for the above question would be to use the "Alias" directive). Let me try to better explain what I want (it's 2:15am here so bear with me).
My apache directory structure is as follow: /var/www/htdocs <- apache document root /var/www/cgi-bin <- cgi-bin script root In my apache.conf file, I have set DocumentRoot "/var/www/htdocs" ServerAlias /cgi-bin/ "/var/www/cgi-bin/" So when "www.mydomain.com/somepage.html" is requested, "/var/www/htdocs/somepage.html" is served. And when "www.mydomain.com/cgi-bin/somescript.cgi" is requested, "/var/www/cgi-bin/somescript.cgi" is served. But now I want some special cases: When "www.mydomain.com/concepts/clientA/somepage.html" is requested, "/home/concepts/clientA/htdocs/somepage.html" is served. When "www.mydomain.com/concepts/clientA/cgi-bin/somescript.cgi" is requested, "home/concepts/clientA/cgi-bin/somescript.cgi" is served. Like I said, I don't want to add a directive for each client. So I don't want this in my apache.conf: Alias "/concepts/clientA/cgi-bin/" "/home/concepts/clientA/cgi-bin/" Alias "/concepts/clientA/" "/home/concepts/clientA/htdocs/" Alias "/concepts/clientB/cgi-bin/" "/home/concepts/clientB/cgi-bin/" Alias "/concepts/clientB/" "/home/concepts/clientB/htdocs/" etc. I want something like this: Alias "/concepts/*/cgi-bin" "/home/concepts/*/cgi-bin/" Alias "/concepts/*/" "/home/concepts/*/htdocs/" Hope that makes sense (like I said, it's 2:15am here and I'm tired :)). |
Got it. Was easier than I thought it would be:
AliasMatch ^/concepts/(.*?)/(.*) /home/concepts/$1/htdocs/$2 ScriptAliasMatch ^/concepts/(.*?)/cgi-bin/(.*) /home/concepts/$1/cgi-bin/$2 Just never knew those two directives existed. :) |
All times are GMT -5. The time now is 06:46 AM. |