Forum Moderators: phranque

Message Too Old, No Replies

Lost Hope To mod_rewrite and subdomains

pretty much, given up hope.

         

ekyl

6:13 am on Jun 7, 2005 (gmt 0)

10+ Year Member



This is my first post here but ive studied coding up and down and a half when I needed help. I decided to make an account because this time, even with all the mod_rewrite threads on this forum, my attempts were useless. Anyway, I am trying to create dynamic subdomains this.example.com and redirect them to example.com/mi/showprofile.php?usershow=this . This is the little code I have compiled on my own:

RewriteEngine on
RewriteCond %{HTTP_HOST}!^(www\.)?example\.com [NC]
RewriteCond %{HTTP_HOST} ^(.+)\.example\.com [NC]
RewriteRule .* /beta/mi/showprofile.php?usershow=%1 [R=301,L]

Some of it is code based from here but some isn't. I need insite pretty much on what to do and would like to know what im doing, not just get the code.

Thanks.

roldar

6:27 am on Jun 7, 2005 (gmt 0)

10+ Year Member



Options +FollowSymlinks
RewriteEngine On

#Be sure subdomain is not www
RewriteCond %{HTTP_HOST}!^www [NC]

#Extract the subdomain
RewriteCond %{HTTP_HOST} ^([^.]+)\.example\.com [NC]

#Do internal rewrite from subdomain to script
RewriteRule ^$ /beta/mi/showprofile.php?usershow=%1 [L]

--------------

I'm afraid I can't do much more explaining due to my lack of understanding, but I was in the same boat as you a while back and this is what I finally got to work.

roldar

7:03 am on Jun 7, 2005 (gmt 0)

10+ Year Member



Also be sure you have wildcard DNS enabled on your server, or it won't work.

itsmani1

7:41 am on Jun 7, 2005 (gmt 0)



{HTTP_HOST}!^ => what does this mean?

jd01

8:40 am on Jun 7, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi ekyl,

How exactly is this not working and, are you trying to redirect 'silently' and serve the information to the subdomain from the same domain, or redirect externally and send the browser to the main domain where the information is?

I ask, because it appears you would like to serve the information to the sub, but you are using a R=301, external flag, so I am not sure I understand.

The second question I have is where are you actually serving the information from, because there seems to be a conflict in this path:
example.com/mi/showprofile.php?usershow=this

And this path from your rule:
/beta/mi/showprofile.php?usershow=%1

RewriteEngine on
RewriteCond %{HTTP_HOST}!^(www\.)?example\.com [NC]
RewriteCond %{HTTP_HOST} ^(.+)\.example\.com [NC]
RewriteRule .* /beta/mi/showprofile.php?usershow=%1 [R=301,L]

Overall, it looks like you are close though. I am sure someone will be able to help you get there soon.

One little adjustment I can suggest if you will be checking every file is to change the left side of your rule to:
RewriteRule . /

If you are not going to store the information in a variable, it is faster to just check and see if a character exists in the request than to process the entire request.

There is also a slight HTTP 1.0 client conflict, because they do not send HOST headers, but this can be corrected with:

RewriteCond %{HTTP_HOST} .

as the first condition. Of course this would then cause another conflict, because they will not be served the correct information since they are not redirected, but I'll let you decide on how to handle that, or maybe it can be addressed more fully later.

Hope this helps.

Justin

BTW {HTTP_HOST}!^ //means 'if the host in the http header is not...'

ekyl

11:47 am on Jun 7, 2005 (gmt 0)

10+ Year Member



roldar, I think that's where im falling short. My just told me this as well. They said I needed to purchase a dedicated IP.

ekyl

11:50 am on Jun 7, 2005 (gmt 0)

10+ Year Member



I want to "redirect externally and send the browser to the main domain where the information is?".

Umm, Im currently seeing about getting a dedicated IP because that may be the problem.

roldar

4:11 pm on Jun 7, 2005 (gmt 0)

10+ Year Member



Yeah you definitely need a dedicated IP address to get it to work. Usually they're only a couple bucks a month.

ekyl

5:36 pm on Jun 7, 2005 (gmt 0)

10+ Year Member



I purchased it but as well as this, my friend told me there is something with CNAME in the DNS zone I have to edit. I had no idea what he was talking about.

Anybody have a clue on this?

roldar

2:27 am on Jun 8, 2005 (gmt 0)

10+ Year Member



...there is something with CNAME in the DNS zone I have to edit.

That's probably the wildcard DNS he's talking about.

I'm not exactly sure what entry you need to make, but if you ask your host they'll probably do it for you.

Essentially what wildcard DNS is doing is putting an '*' in front of your domain name, allowing the server to accept anything instead of just www, mail, ftp, etc. If you don't have this entry it will just ignore all other subdomains.

ekyl

6:54 pm on Jun 8, 2005 (gmt 0)

10+ Year Member



Yeah, I got a friend to help me figure it out.
Thanks a lot for the help, I got it working.