Forum Moderators: phranque
I want to allow these people to just type in myusername.domain.com and have it bring up the page www.mydomain.com/mypage.php?id=myusername, but I want the address bar to remain at myusername.domain.com.
I've got the following .htaccess file, but every time I try to enter myusername.domain.com it doesn't work at all.
RewriteEngine On
# Extract the subdomain part
RewriteCond %{HTTP_HOST} ^([^.]+)\.domain\.com$ [NC]
# Verify it's not ``www''
RewriteCond %1!^www$ [NC]
# Make a proxy redirection
RewriteRule ^.*$ [domain.com...] [P,L]
Does anybody have a suggestion?
Options +FollowSymlinks
RewriteEngine On
# Extract the subdomain part
RewriteCond %{HTTP_HOST} ^([^.]+)\.domain\.com$ [NC]
# Verify it was not www
RewriteCond %1!^www$ [NC]
# Do internal redirection for a request as
RewriteRule ^$ /mypage.php?id=%1
Options +FollowSymlinks
RewriteEngine On
# Verify subdomain is not www
RewriteCond %{HTTP_HOST} !^www [NC]
# Extract the subdomain part
RewriteCond %{HTTP_HOST} ^([^.]+)\.domain\.com [NC]
# Do internal rewrite from subdomain/ to script with id
RewriteRule ^$ /mypage.php?id=%1 [L]
Jim
The other possibility I've considered is that mod_rewrite isn't turned on. Is there some place where I can find out if mod_rewrite is on?
Does anybody else do this "virtual subdomain" creation with .htaccess? If so, would you mind sticky-mailing me the name of your webhost so I can take a look at their plans? I've run into more than a couple problems with my current host and I think I should find a good one before my site gets much activity.
The simplest way to find out if mod_rewrite is enabled is to make a test rule:
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^silly\.html$ /index.html [L]
In order for this subdomain plan to work, you must have wild-card DNS set up to point all subdomains to your server, and your host must point all subdomain requests to your Web root directory where the .htaccess code is installed.
Jim