www.username.site.com to www.site.com/test.php?user=username

Ask your mod_rewrite and Redirection questions here, and get answers!

www.username.site.com to www.site.com/test.php?user=username

Postby john » 13 May 2008 23:16

Hello.
I'm needing some serious help in resolving a problem.
I need to create some "virtual subdomains" for a site.
So the structure would be like this:
I have site.com
and site.com/test.php?user=username
and I want that the "test.php" page, with the query string to be accessible from username.site.com.
I cannot create the subdomains from the cPanel.
So basically, the subdomain doesn't exist, but if a user enter the url: http://www.username.site.com i want to redirect him (silent) to http://www.site.com/test.php?user=username.
Please help me, cause I have tried all the examples from this forum that seemed to relate with my problem, but i still get a 404 error message.
Thanks,
John.
john
 
Posts: 3
Joined: 13 May 2008 23:07

Re: www.username.site.com to www.site.com/test.php?user=username

Postby john » 14 May 2008 00:15

Hello again,
I have studied more this problem and I have another question: does the host that hosts my site must approve this qind of htaccess usage or I need a special setting from the host?
John.
john
 
Posts: 3
Joined: 13 May 2008 23:07

Re: www.username.site.com to www.site.com/test.php?user=username

Postby john » 14 May 2008 06:43

I Have Found the ANSWER (Of course, without any of your help, guys, thanks for nothing ;-)

So, If anybody is interested, this problem has a dual-solving component:
First of all, the administrator of the server where the site is hosted must configure the httpd.conf to accept wildcard dns.
Then, u must write some code into the .htaccess file.
The code is as follows:


Code: Select all
#start of code
Options +FollowSymLinks
RewriteEngine on
RewriteBase /

RewriteCond %{HTTP_HOST} ^www\.([^.]+)\.yoursite\.com$ [NC]
RewriteRule ^$ http://www.yoursite.com/dinamicpage.php?value=%1 [L]

#end of code


So if u want to have http://www.username.yoursite.com as a virtual subdomain redirect to yoursite.com/a-page.php?user=username, u must:
1. contact your admin host (the firm that is hosting your site) and ask them to allow you to have virtual subdomains (they must allow you to have wildcard dns, this is a setting that must be done in the httpd.conf file on the server)
2. write the code above inside the .htaccess file

Hope this post will help many users.
John.
john
 
Posts: 3
Joined: 13 May 2008 23:07


Return to Redirect or Rewrite Questions



Who is online

Users browsing this forum: clerkfurniture, HIBcokyacrornsap, LOTVodaPeece, ShakhtarrDon, VocrepeAcceby, Zitioutbava