Forum Moderators: phranque

Message Too Old, No Replies

Prepending Customer Names to Main Server Name

Am I on the Right Track With Rewrite?

         

Dogvan

8:08 pm on Dec 18, 2007 (gmt 0)

10+ Year Member


I am looking to allow my customers, e.g. Smith to type in http://smith.mysite.com and get to http://www.mysite.com/smith/

From the Apache 2.2 docs I tried putting the following in my virthost container

RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.[^.]+\.mysite\.com
RewriteRule ^(.+) %{HTTP_HOST}$1 [C]
RewriteRule ^www\.([^.]+)\.mysite\.com(.*)www.mysite.com/$1$2

I set RewriteLogLevel 9 and can see that comparisons are indeed being made for every VALID page request, but 404s never seem to be compared at all. And you know in my naieve frustration I can't help but think they wouldn't even BE 404s if they were compared and rewritten first! And while I do think that last sentence may be the key, I still can't see it. Can someone point me toward the highway? Thanks in advance.

FWIW my webmaster skills rely heavily on the ctrl-C and ctrl-V keyboard combinations

:)

(I'm only half-kidding)

jdMorgan

8:30 pm on Dec 18, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This modified version will canonicalize "www.user.example.com" to "user.example.com" and enforce valid and all-lowercase usernames. It further allows storage of username directories in a subdirectory named "user_dirs" so as to avoid naming conflicts with other subdirectories in your main site's top-level directory:

RewriteEngine on
#
# Redirect to canonicalize www.username.example.com to username.example.com
RewriteCond %{HTTP_HOST} ^www\.([^.]+)\.example\.com
RewriteRule ^/(.*)$ http://%1.example.com/$1 [R=301,L]
#
# Rewrite useername.example.com/<filename> to /user_dirs/useranme/<filename>
RewriteCond $1 !^user_dirs/
RewriteCond %{HTTP_HOST} !^www\.example.com
RewriteCond %{HTTP_HOST} ^([a-z][a-z0-9\-]*[a-z0-9])\.example\.com
RewriteRule ^/(.*)$ www.mysite.com/user_dirs/%1/$1 [L]

The second rule maps the URL http://customer-1.example.com/cust1file.html to the server filespace /user_dirs/customer-1/cust1file.html

To avoid additional problems, you should require that all customers use subdomain names containing an all-lowercase alphabetic character to start, lowercase alphabetic, numeric or hyphen characters in the middle, and a lowercase alphabetic or numeric character to end. This is to comply with the HTTP URL-naming conventions, and to prevent access problems using the code above.

Jim

Dogvan

9:01 pm on Dec 18, 2007 (gmt 0)

10+ Year Member


Thanks so much for that. You need a paypal tip jar.

I accidentally gave some wrong information. When I type in http://smith.mysite.com I get an immediate DNS error, not a 404. So I apologize for that. And of course that's why there's no comparison in the Rewrite log!

I get that in both IE6 and IE7, so I'm going to go investigate the workings of these mysterious DNS records. hanks again for your help.

[1][[b]edited by[/b]: Dogvan at 9:01 pm (utc) on Dec. 18, 2007][/1]

jdMorgan

10:30 pm on Dec 18, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You'll need to set up 'wildcard DNS' to support the customer subdomain names, either by adding a new 'A Record' or by modifying the existing one to read "*.example.com." <-- Note that trailing period, usually required, and include it if your original setup already includes it.

Jim

Dogvan

1:39 pm on Dec 19, 2007 (gmt 0)

10+ Year Member



Thanks again. I had already set up the wildcard A record yesterday but forgot that trailing period and indeed it was jacked up. Specifically, the entry showed the main host name twice in a row. So thanks again for saving me a couple days before I went back wondering what was wrong.

I can't help but think that every site would want to see all traffic ending in their own domain name, that hosts would steer you toward a wildcard record by default. We're on a Verio VPS3 and that company, at least, does not breathe a word of it in the dummy self-help pages.

jdMorgan

1:49 pm on Dec 19, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



> I can't help but think that every site would want to see all traffic ending in their own domain name, that hosts would steer you toward a wildcard record by default.

Wildcard DNS creates an opportunity for 'infinite duplicate-content' problems. Once you define wild-card DNS, it is up to you to be sure that each page on your site can be reached using one URL and one URL only. All the rest must return a permanent redirect, a 404-Not Found, or a 410-Gone response. To neglect this is to hand an axe to your most aggressive competitors, and ask them not to hit you... ;)

Hosting companies provide servers, and cannot be expected to provide in-depth training to their customers on advanced server configuration, SEO, and SEM topics. With the current pressure on hosting fees, it's a wonder they provide as much info as they do.

Jim