SOLVED: An Apache URL Rewriting Challenge
Posted: Sat Mar 27, 2004 9:09 pm
Today is the first day of my short spring break, so it is time to turn my attention back to unfinished books and unfinished software development projects. Here is something I thought of long ago:
I have been wondering if I can dynamically rewrite the URL for any file or directory that is requested via a particular host name when multiple host names point to the same Web space. If so, I could enable customizable domain parking and small-scale virtual hosting for Web sites that do not need their own individual logs and such (notices about domain changes, quick reference pages, etc.). Here is an example of the sort of page for which something like this is useful:
http://www.monthlycalendars.com/
That is a one-page Web site that I have up to tell visitors to the old domain that the name of the site and its corresponding domain have both changed.
Unfortunately, I have thus far been unable to redirect an entire domain to a subdirectory without redirecting each individual file like so:
RewriteCond %{HTTP_HOST} ^(www\.)?somedomain\.tld$ [NC]
RewriteRule ^file.ext$ /directory/directory/file.ext
I have tried various permutations of the following in .htaccess files (my Web sites are hosted on shared servers, so I do not have access to the server configuration files), but without success:
RewriteCond %{HTTP_HOST} ^(www\.)?somedomain\.tld$ [NC]
RewriteRule ^/(.*) /directory/directory/$1 [L]
Any ideas? http://httpd.apache.org/docs/mod/mod_rewrite.html and http://httpd.apache.org/docs/misc/rewriteguide.html provide some useful information and the "Moved DocumentRoot" example on the latter page looked promising, but a working solution--if indeed one exists--thus far eludes me.
For those still reading this uncharacteristically long forum post, my Web sites are currently running under Apache 1.3.7 on Debian GNU/Linux (kernel version 2.4.24).
Thank you in advance for any good information.
I have been wondering if I can dynamically rewrite the URL for any file or directory that is requested via a particular host name when multiple host names point to the same Web space. If so, I could enable customizable domain parking and small-scale virtual hosting for Web sites that do not need their own individual logs and such (notices about domain changes, quick reference pages, etc.). Here is an example of the sort of page for which something like this is useful:
http://www.monthlycalendars.com/
That is a one-page Web site that I have up to tell visitors to the old domain that the name of the site and its corresponding domain have both changed.
Unfortunately, I have thus far been unable to redirect an entire domain to a subdirectory without redirecting each individual file like so:
RewriteCond %{HTTP_HOST} ^(www\.)?somedomain\.tld$ [NC]
RewriteRule ^file.ext$ /directory/directory/file.ext
I have tried various permutations of the following in .htaccess files (my Web sites are hosted on shared servers, so I do not have access to the server configuration files), but without success:
RewriteCond %{HTTP_HOST} ^(www\.)?somedomain\.tld$ [NC]
RewriteRule ^/(.*) /directory/directory/$1 [L]
Any ideas? http://httpd.apache.org/docs/mod/mod_rewrite.html and http://httpd.apache.org/docs/misc/rewriteguide.html provide some useful information and the "Moved DocumentRoot" example on the latter page looked promising, but a working solution--if indeed one exists--thus far eludes me.
For those still reading this uncharacteristically long forum post, my Web sites are currently running under Apache 1.3.7 on Debian GNU/Linux (kernel version 2.4.24).
Thank you in advance for any good information.