Forum Moderators: phranque

Message Too Old, No Replies

Dynamic subdomains in htaccess

Dynamic subdomains

         

easyway

8:53 am on Sep 20, 2006 (gmt 0)

10+ Year Member



Hi,
I have to configure dynamic subdomains.So I have enabled wildcard DNS.
Now the requirement is this.
When I request
[subdom1.mysite.com...] should call [mysite.com...]
But the URL should be remain as [subdom1.mysite.com...]

below .htaccess lines are ok. But it redirected to [mysite.com...]
When I remove [R] , it's giving internal server error.

RewriteCond %{HTTP_HOST}!^www\.mysite\.com
RewriteCond %{HTTP_HOST} ([^.]+)\.mysite\.com$ [NC]
RewriteRule ^(.*)$ [mysite.com...] [R]

Pls. let me know any solution for this.

jdMorgan

12:44 pm on Sep 20, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The syntax for an internal rewrite and an external redirect differs by more than just the [R] flag. Also, you may need to explicitly prevent a rewrite loop by testing for an already-rewritten URL:

RewriteCond %{HTTP_HOST} !^www\.example\.com
RewriteCond %{HTTP_HOST} ([^.]+)\.example\.com
RewriteCond %{REQUEST_URI} !^/booklist\.php$
RewriteCond %{QUERY_STRING} !^id=.
RewriteRule (.*) /booklist.php?id=%1 [L]

Because your description and example don't quite match, you may need to adjust this code -- I can't be sure. But it should get you started.

Jim

easyway

2:39 pm on Sep 20, 2006 (gmt 0)

10+ Year Member



hi Jim,
This is the exact solution what I need. I have implemented and it’s working now.
Thanks for the help.