Easy mod_rewrite Faux subdomains!

Okay, so recently a I ran across this age old question over at the good ole Pixel2Life forums the other day decided I was curious about it myself.

The best one I found came from WebDeveloper.com. I was able to get it up and working on the first try but the only thing I really didn’t like is that it redirected my browser to the PHP page, which I really didn’t like and looked quite ugly.


RewriteEngine On
# Extract the subdomain part of domain.com
RewriteCond %{HTTP_HOST} ^([^\.]+)\.domain\.tld$ [NC]
# Check that the subdomain part is not www and ftp and mail
RewriteCond %1 !^(www|ftp|mail)$ [NC]
# Redirect all requests to a php script passing as argument the subdomain
RewriteRule ^(.*)$ index.php?u=%1 [L]

 

 


So, this is what I came up with. Essentially, you can enter in “http://anything.domain.com” and “anything” will be passed to $_GET[”u”] without the user being visually aware of any PHP script being used.

 

htaccess mod rewrite php sub domains

First day!

So, it’s been a good day today. Sun shining, tons of availability at work so I am able to get some other work done. :)
Anyways, so here’s where I am… 

Cereal 

  • 1 Cup Kashi GoLean Crunch (190 calories)
  • 1/2 Cup 2% milk (120 calories)

2 PB&J sandwiches

  • 4 slices wheat bread (320 calories)
  • 4 Tbsp JIF peanut butter (380 calories)
  • 2 Tbsp grape jelly (140 calories)
  • 1 serving FunYuns chips (140 calories)
  • Soda - Cherry Coke (150 Calories)

Total caloric intake: 1400 



Design by: Derek Punsalan
Spammers stopped: 1
RSS