Forum Moderators: phranque
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST}!www.webpage.com$ [NC]
RewriteCond %{HTTP_HOST} ^(www.)?([a-z0-9-]+).webpage.com/([a-z0-9-]+) [NC]
RewriteRule .* %2/%3 [L]
This code works to some extent, but it redirects to the folder instead of being transparent.
Thank you for all future help.
RewriteEngine on
RewriteBase /
#
RewriteCond $1 !^subs/
RewriteCond %{HTTP_HOST} !^www\.example\.com [NC]
RewriteCond %{HTTP_HOST} ^(www\.)?([a-z0-9\-]+)\.example\.com
RewriteRule (.*) /subs/%2/$1 [L]
The critical problem with your code was that it was attempting to get the URL-path (%3) from the HTTP_HOST. But the URL-path is not part of HTTP_HOST.
Allow only lowercase subdomains; Apache will treat /subs/my-sub as a different directory than /subs/My-Sub
Also, either do not end-anchor the domain name patterns, or add (:[0-9]+)?$ to the end, in order to allow for valid port numbers passed by some clients in the HTTP "Host:" header.
Jim
[edited by: jdMorgan at 10:56 pm (utc) on Nov. 22, 2007]
Also make sure that the ErrorDocument directive specifies a local filepath, not a canonical URL! If it specifies a URL, the status code returned to the client will be a 302-Found, not a 404-Not Found, as described in the ErrorDocument documentation.
Jim
[edited by: jdMorgan at 11:26 pm (utc) on Nov. 22, 2007]