Forum Moderators: phranque
I want to redirect students.example.nl to www.example.nl/students. It should be invisible, so the first URL students.example.nl should stay in the browsers URL.
I tried to put in .htaccess:
RewriteEngine On
RewriteCond %{http_host} ^studenten.example.nl [NC]
RewriteRule ^(.*)$ http://www.example.nl/indexS.htm [L]
But http://www.example.nl/indexS.htm appears and that should be hidden from the user.
Pleas advise,
Louis Banens
RewriteEngine on
#
RewriteCond $1 !^users/
RewriteCond %{HTTP_HOST} !^www\.example\.com
RewriteCond %{HTTP_HOST} ^([a-z]([\-_]?[0-9a-z]+)+)\.example\.com
RewriteRule (.*) /users/%1/$1 [L]
We have added the requirement for a 'master' subdirectory called "users" for three reasons: First, to make it easy to detect and stop the recursion described above, second, to help you keep your site's files organized over time as the number of users gets large, and finally, to prevent someone from signing up with the username "cgi-bin" and gaining direct access to your /cgi-bin script files, as just one example.
Note that the character-set of the subdomains is restricted to ensure a valid HTTP subdomain, with 'safe' lowercase alphabetic characters, numbers, hyphens and underscores only in acceptable positions.
Also, note that lowercase characters are not accepted, because Apache will treat *any* upper/lowercase variation as *different* directories. This could lead to user confusion, and also to apparently-duplicate usernames: For example, "michele.example.com" and "Michele.example.com" would be treated as two different users, and would be mapped to two different subdirectories. The minimum supported username/subdomain length with this code is two characters. Each username/subdomain must start with a letter. It may contain non-contiguous hyphens or underscores, and must end with a letter or number. This will keep you in compliance with the HTTP/1.1 requirements for domain naming.
Note also that the "www.example.com" subdomain is *not* mapped to a 'user' directory.
You should also add another rule to 301-redirect www.<studenten>.example.com/xyz and <studenten>.www.example.com/xyz to <studenten>.example.com/xyz to prevent common user errors and confusion about using "www".
Jim