-2

Possible Duplicate:
Apache rewrite based on subdomain

I am stuck with one problem which not able to solve it. Plz help me to come out of this.

My requirement is: I want to have each city name as sub domain in my site. Say www.mysite.com, which can have www.delhi.mysite.com, www.bangalore.mysite.com. The list might go endless. My problem is I don't want to create folders for each of the sub domains. I want to handle it in the URL as query string, say www.mysite.com?city=bangalore. This way I can redirect the request to a single file.

I have made the set up LAMP architecture.

In vhost file, it is

<VirtualHost 127.0.0.1:80>
ServerAdmin webmaster@localhost
ServerName www.mysite.com
DocumentRoot /var/www
</VirtualHost>

<VirtualHost 127.0.0.1:80>
ServerAdmin webmaster@localhost
ServerName *.mysite.com
DocumentRoot /var/www
</VirtualHost>

and Also updated .htaccess

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.mysite\.com [NC]
RewriteCond %{HTTP_HOST} ([^.]+)\.mysite\.com
RewriteRule ^(.*)$ http://www.mysite.com/index.html [R,L]

But still I am getting 404 error.

Is my approach correct?? Can it be achievable??

Please help me in doing this.

Community
  • 1
  • 1
Ram
  • 1
  • 3
  • 3
    likely duplicate of: http://stackoverflow.com/questions/49500/apache-rewrite-based-on-subdomain http://stackoverflow.com/questions/4193651/simple-htaccess-subdomain-rewrite http://serverfault.com/questions/203780/troubleshooting-a-htaccess-wildcard-subdomain-rewrite/203804#203804 – Has QUIT--Anony-Mousse Dec 12 '11 at 20:27

1 Answers1

0

Try something along these lines:

RewriteCond %{HTTP_HOST} ^([^.]+)\.domain\.com$
RewriteRule ^/(.*)$           http://www.domain.com/%1/$1 [L,R]

plus a rule to not apply this to the www prefix.

And next time, please use the search function, this has been asked before.

Make sure you have enabled the rewrite module. Try putting the statements into your vhost config instead of .htaccess.

Has QUIT--Anony-Mousse
  • 76,138
  • 12
  • 138
  • 194