I'm able to use virtual subdomains with my hosting company, so what
I'd like to do is have addresses like:
apple.mysite.com
banana.mysite.com
go to
http://www.mysite.com/fruit.html?fruit=apple
http://www.mysite.com/fruit.html?fruit=banana
I've setup my .htaccess to allow this, so when I visit
apple.mysite.com it does redirect me to http://www.mysite.com/fruit.php?fruit=apple,
but I want the browser address bar to stay at http://apple.mysite.com
while serving the data from the "fruit.html" file, in this example.
What am I missing?
My .htaccess is
Options +FollowSymLinks
RewriteEngine on
# Extract the subdomain part of domain.com
RewriteCond %{HTTP_HOST} ^([^\.]+)\.mysite\.com$ [NC]
# Check that the subdomain part is not www and ftp and mail
RewriteCond %1 !^(www|ftp|mail)$ [NC]
# Redirect all requests to a php script passing as argument the
subdomain
RewriteRule ^.*$ http://www.mysite.com/fruit.php?fruit=%1 [QSA,L]
TIA
Jeff
Rewrites manipulate the mapping of URLs to files, unless destination is NOT
a file or folder.
While at it:
- assuming www is the most commonly used prefix, test it first
-and save some time not spent on the other condition-
- assuming 'domain.com' is a constant and the only domain served, don't
test it
- why testing the discarded URL for perhaps having characters between
_start_ and_ end_?
checking for a single character should [in theory] stop right after the
first one
Try these untested lines:
RewriteCond %{HTTP_HOST} !^(www|ftp|mail)\. [NC]
RewriteCond %{HTTP_HOST} ^([^\.]+)\.
RewriteRule .? fruit.php?fruit=%1 [QSA,L]
HansH
Hans, excellent! That worked. Thank you for your help
Jeff