mod rewrite - .htaccess redirect to another domain using wildcard subdomains -


i have looked around here day, , although have seen similar questions , have managed partial answer question, still missing 1 major part.

the thing trying is, have dynamic subdomains (for instance username.mydomain.dk) use within system.

what have managed far:

  1. change dns support wildcard, *.mydomain.dk
  2. make .htaccess redirect main domain (www.simon-smith.dk)
  3. successfully view mydomain.dk page

now problem here is, have few websites sharing same ip address. www.simon-smith.dk main domain , mydomain.dk on ip. therefore when requesting *.mydomain.dk www.simon-smith.dk first. here have added following in .htaccess:

# *.mydomain.dk redirectd rewritecond %{http_host} !^www\.mydomain\.dk$ [nc] rewritecond %{http_host} ^(.*)\.mydomain.dk$ [nc] rewriterule ^(.*)$ http://mydomain.dk/?subrequest=%1 [p,l,qsa] 

here using p flag other domain, apparently blocks rewrite rules on mydomain.dk, follows:

# match not have language code rewritecond %{request_uri} !^/public/[a-z]{2}/ [nc] rewriterule ^(.*)$ index.php?url=$1 [pt,l,qsa]  # match have language code rewritecond %{request_uri} !^/public/js/ rewriterule ^([a-z]{2})/(.*)$ index.php?lang=$1&url=$2 [pt,l,qsa] 

i can access subrequest parameter url without problem, url parameter not registered longer.

is there way use .htaccess redirect, or have webserver mydomain.dk main domain have redirect done properly?

having dug bit further , used ol' trial , error found mistake.

on main domain, www.simon-smith.dk, had append correct request uri work, doing follows:

# *.mydomain.dk redirectd rewritecond %{http_host} !^www\.mydomain\.dk$ [nc] rewritecond %{http_host} ^(.*)\.mydomain.dk$ [nc] rewriterule ^(.*)$ http://mydomain.dk/$1?subrequest=%1 [p,l,qsa] 

Comments