regex - .htaccess rewrite subdomain to directory or to file depending on path -
when navigate sub.domain.com/path gets me domain.com/site.php?site=sub&page=path.
when path text.text want point domain.com/subdomains/sub/text.text can't work together.
rewritecond %{http_host} ^(.*)\.domain\.com$ [nc] rewritecond %{request_uri} !^(.*\..*)$ [nc] rewriterule ^(.*)$ site.php?site=%1&page=$1 [l] when path contains text.text apply rule:
rewriterule ^(.*)$ http://domain.com/subdomains/%1/$1 [p,l,nc,qsa] also how can make rule above work relative path (without http://domain.com/)?
update:
sub.domain.com -> site.php?site=sub sub.domain.com/path -> site.php?site=sub&page=path sub.domain.com/path.ext -> subdomains/sub/path.ext all above works, 1 more left:
sub.domain.com/constant/text.text -> constant/text.text that 1 above should apply if after constant text dot. if not rule should apply:
sub.domain.com/path -> site.php?site=sub&page=path
you can use these 2 rules:
rewriterule ^(constant|site\.php$) - [l,nc] # path no dot rewritecond %{http_host} ^(.+?)\.domain\.com$ [nc] rewriterule ^/?$ site.php?site=%1 [l,qsa] rewritecond %{http_host} ^(.+?)\.domain\.com$ [nc] rewriterule ^([^.]+)/?$ site.php?site=%1&page=$1 [l,qsa] # else i.e. path dot rewritecond %{http_host} ^(.+?)\.domain\.com$ [nc] rewriterule ^(.+)$ http://domain.com/subdomains/%1/$1 [p,l,nc]
Comments
Post a Comment