Subdomain to script as parameter and address change

Using a single web hosting account to host multiple sites

Subdomain to script as parameter and address change

Postby nf » Sat Feb 07, 2009 5:06 am

Dears,

At the moment I'm rewriting subdomain to script as parameter:
Code: Select all
USER.domain.pl to domain.pl/script.php?id=USER

(with or w/o WWW) in such way:
Code: Select all
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{HTTP_HOST} !^www\.domain\.pl$ [NC]
RewriteCond %{HTTP_HOST} ^(www\.)?([^\.]+)\.domain\.pl$ [NC]
RewriteRule ^$ /script.php?id=%2 [QSA,L]


QUESTION:

My users are used to subdomain addresses but due to AJAX issues with subdomains I want to change this rule to redirect like that:
Code: Select all
USER.domain.pl to domain.pl/folder/USER

(with or w/o WWW) and have page address in address bar without subdomain - only this way:
Code: Select all
http://domain.pl/folder/USER

(with or w/o WWW)

Thanks a lot!
nf
 
Posts: 12
Joined: Thu Dec 04, 2008 6:26 am

Postby richardk » Sat Feb 07, 2009 12:04 pm

Try
Code: Select all
Options +FollowSymlinks

RewriteEngine On

RewriteCond %{HTTP_HOST} !^www\.example\.pl$ [NC]
RewriteCond %{HTTP_HOST} ^(www\.)?([^\.]+)\.example\.pl$ [NC]
RewriteRule ^$ /folder/%2 [QSA,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby nf » Sat Feb 07, 2009 1:51 pm

Unfortunately this doesn't work at all - also in address bar typed address remains unchanged like that:
Code: Select all
http://USER.domain.pl

instead of:
Code: Select all
http://domain.pl/folder/USER


Might be that in such case I should not use wildcard subdomains?
nf
 
Posts: 12
Joined: Thu Dec 04, 2008 6:26 am

Postby richardk » Mon Feb 09, 2009 8:33 am

Try
Code: Select all
Options +FollowSymlinks

RewriteEngine On

RewriteCond %{HTTP_HOST} !^www\.example\.pl$ [NC]
RewriteCond %{HTTP_HOST} ^(www\.)?([^\.]+)\.example\.pl$ [NC]
RewriteRule ^$ /folder/%2 [R=301,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby nf » Mon Feb 09, 2009 1:29 pm

OK, this redirects correctly but there's issue that I don't know how to avoid. In address bar after redirect I still have something like that:
Code: Select all
http://USER.example.pl/folder/USER

which (subdomain) causes AJAX not working well.
Just want to know how to have in address bar address changed into:
Code: Select all
http://example.pl/folder/USER


===UPDATE===

To solve the issue I used such rule:
Code: Select all
RewriteRule ^$ http://example.pl/folder/%2 [R=301,L]

but it's visible that this redirect is very slow.

Thank you!
nf
 
Posts: 12
Joined: Thu Dec 04, 2008 6:26 am


Return to Domain Handling

Who is online

Users browsing this forum: No registered users and 26 guests

cron