mod_rewrite for subdomains
Posted by: dambro
Posted on: 2007-11-15 22:26:00
This question is posted in numerous threads throughout the internets. Unfortunately, none seem to contain a solution that works. I hope someone will be able to help me here.
I would like to write a mod_rewrite script that takes the domain: http://place.site.com and sends http://site.com?n=$place to the user's browser.
here's my script:
<IfModule mod_rewrite.c>
Options +FollowSymLinks
Options +Indexes
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !www.site.com$ [NC]
RewriteCond %{HTTP_HOST} ^(www.)?([a-z0-9-]+).site.com [NC]
RewriteRule (.*) www.site.com/index.php [L]
</IfModule>
You'll notice I'm not sending any variables in my RewriteRule. For right now, I'll be happy if I can just redirect a call for a subdomain to the index of the main site.
1) Yes, I have contacted Dreamhost, and they have turned on the wildcard subdomains for me.
2) This script does work if I write this for the RewriteRule:
RewriteRule (.*) http://www.site.com/index.php [L]
But this redirects the entire site, instead of maintaining the subdomain in the url while displaying the main site in the browser.
3) I have also tried using my full root address in the RewriteRule: /home/username/www.site.com/index.php. That doesn't work either.
What am I doing wrong?