mod_rewrite for subdomains

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?

Re: mod_rewrite for subdomains

Posted by: Atropos7
Posted on: 2007-11-16 04:50:00

In reply to:

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....

What am I doing wrong?



Uh, when the hostname changes, it will be a redirect. Unless you pass it through a proxy. So did you ask DreamHost if they allow / support using the proxy module and did you read the Apache documentation?

cool openvein.org -//- One-time $50.00 discount on DreamHost plans: Use ATROPOS7Edited by Atropos7 on 11/16/07 04:55 AM (server time).

Tags: mod rewritesubdomainsthreads