Mod_rewrite for subdomains

software development

#1

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:

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]

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?


#2

[quote]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?[/quote]

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 [color=#6600CC]$50.00 discount[/color] on [color=#0000CC]DreamHost[/color] plans: Use ATROPOS7