Reputation: 66480
This almost the same as .htaccess rewrite subdomain to directory
this solution works:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^([^.]+)\.jcubic\.atthost24\.pl$
RewriteRule ^((?!subdomains/).*)$ /subdomains/%1/$1 [L,NC,QSA]
but I would like to forward but without /subdomains directory so
http://img.jcubic.atthost24.pl/.*
should read http://jcubic.atthost24.pl/img/.*
Is this possible? This doesn't work
RewriteRule ^((?!%1/).*)$ /%1/$1 [L,NC,QSA]
I'm not sure what version of Apache I have.
Upvotes: 0
Views: 33
Reputation: 42885
This probably is what you are looking for:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^img\.jcubic\.atthost24\.pl$
RewriteRule ^/?(.*)/?$ /img/$1 [END,QSA]
Note however that you should try to place such rules inside the http server's host configuration instead of using dynamic configuration files (".htaccess").
Above rule will work in both situations, though.
In case you get an internal error (http status 500) check the error log file. If it complains about an unknown END
flag, then you probably operate a very old version of the apache http server. In that case try the L
flag, it shoulod work the same here, though that actually depends on the specific situation.
UPDATE, according to your comment:
In case the hostname "img" is to be treated in a dynamic manner you can do that:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^([^.]+)\.jcubic\.atthost24\.pl$
RewriteRule ^/?(.*)/?$ /%1/$1 [END,QSA]
Maybe you want to add a check for whether that folder actually exists in the physical file system of the http server.
Upvotes: 1