url rewriting - URL Rewrite => Variable to Subdomain -


in .htaccess file, code works fine :

rewritecond %{http_host} ^(.+).mydomain.com$   
rewriterule ^(.*)$ http://mydomain.com/profile.php?username=%1 [r,l]

for example, when write url :

http://xxx.mydomain.com

it redirects :

http://mydomain.com/profile.php?username=xxx

but problem want opposite :

when write url :

http://www.mydomain.com/profile.php?username=xxx

i want redirection :

http://xxx.mydomain.com

i tried possibilities, nothing worked.

can me please ?

try this

rewriteengine on rewritebase /  rewritecond %{http_host} !^(www\.)?mydomain\.com$ [nc] rewritecond %{http_host} ^(.+)\.mydomain\.com$ [nc] rewriterule ^.*$ http://www.mydomain.com/profile.php?username=%1 [l] 

okay, www has been made optional.

edit: redirect sub.domain.com/someother/page.php well.

rewritecond %{http_host} !^(www\.)?mydomain\.com$ [nc] rewritecond %{http_host} ^(.+)\.mydomain\.com$ [nc] rewriterule ^(profile\.php)?$ http://www.mydomain.com/profile.php?username=%1 [l] rewriterule ^(.+)$ http://www.mydomain.com/$1 [l] 

this redirect

eli.mydomain.com => http://www.mydomain.com/profile.php?username=eli eli.mydomain.com/profile.php => http://www.mydomain.com/profile.php?username=eli  eli.mydomain.com/contactus.php => http://www.mydomain.com/contactus.php eli.mydomain.com/help/search.php?q=faq => http://www.mydomain.com/help/search.php?q=faq 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -