How to rewrite url to include subdirectory?
- by Jason Roberts
The following set of rewrite rules rewrite any urls formatted as foo.mydomain.com/bar to mydomain.com/mysubs/foo/bar.php. This all works fine except if I have a subdirectory named 'blah' in the original url such as foo.mydomain.com/blah/bar, then it will rewrite it as mydomain.com/mysubs/foo/bar (without the blah subdirectory) when what I need is the url to be rewritten as mydomain.com/mysubs/foo/blah/bar.
So, what do I need to change to make this work correctly?
Options +FollowSymLinks
Options -Indexes
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !www.mydomain.com$ [NC]
RewriteCond %{HTTP_HOST} ^([^./]+)\.mydomain\.com$
RewriteRule !^mysubs/ mysubs/%1%{REQUEST_URI} [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php