Forum Moderators: phranque

Message Too Old, No Replies

Virtual subdomains

RewriteRule for svirtual subdomain directory

         

Mascka

9:28 am on Dec 26, 2008 (gmt 0)

10+ Year Member



on my site i create virtual subdomains. it works fine. the code is this:
(the code is in the htaccess file in domain root)

RewriteCond %{HTTP_HOST} !^www\.example\.com$
RewriteCond %{HTTP_HOST} ^.+\.example\.com$
RewriteCond %{REQUEST_URI} !^(www¦ftp)$
RewriteCond %{REQUEST_FILENAME} !^/home/example/public_html/
RewriteRule ^(.*)$ %{HTTP_HOST}$1 [C]
RewriteRule ^(.*)\.example\.com/ /index.php?a=prog&det=$1 [QSA,L]


if go to:
h_ttp://pickup.example.com/
is requested this:
http://www.example.com/index.php?a=prog&det=pickup

but if i request:
h_ttp://pickup.example.com/images/

it take me to:
h_ttp://www.example.com/images/ but i need to take me to:
h_ttp://www.example.com/index.php?a=prog&det=pickup&img

i try to add to htaccess code this:
RewriteRule ^(.*)\.example\.com/images/ /index.php?a=prog&det=$1&img[QSA,L]

but no effect. please help me with this problem..

[edited by: coopster at 1:40 pm (utc) on Dec. 26, 2008]
[edit reason] please use example.com, thanks! [/edit]

jdMorgan

3:04 pm on Dec 26, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You don't need to chain rules, but you do need to reproduce any and all RewriteConds for the new rule, and you need to put the most-specific rule first:

RewriteCond %{HTTP_HOST} ^([^.]+)\.example\.com
RewriteCond %1 !^www$
RewriteRule ^images/ /index.php?a=prog&det=%1&img [QSA,L]
#
RewriteCond %{HTTP_HOST} ^([^.]+)\.example\.com
RewriteCond %1 !^www$
RewriteRule !^index\.php$ /index.php?a=prog&det=%1 [QSA,L]

Note that I removed your "RewriteCond %{REQUEST_URI}" because it was broken and would not work, and I removed your "RewriteCond %{REQUEST_FILENAME}" because I could not see why it might be needed.

The modified original rule (now the second rule) checks to be sure that the requested URL-path is not already "index.php" in order to prevent an 'infinite' rewriting loop.

Note that in .htaccess, URL-paths examined by RewriteRule will never start with a slash. However, URL-paths examined using RewriteCond %{REQUEST_URI} will always start with a slash. Design your regular-expressions patterns with this in mind.

RewriteConds apply only to the single RewriteRule that follows them, and that may have been the main problem.

Jim