How to rewrite url to include subdirectory?

Posted by Jason Roberts on Stack Overflow See other posts from Stack Overflow or by Jason Roberts
Published on 2010-05-04T04:00:31Z Indexed on 2010/05/04 4:08 UTC
Read the original article Hit count: 296

Filed under:
|

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

© Stack Overflow or respective owner

Related posts about rewrite

Related posts about mod-rewrite