Welcome to WebmasterWorld Guest from

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

How to invisible indirect

5:35 pm on Jan 30, 2009 (gmt 0)

New User

5+ Year Member

joined:Jan 30, 2009
posts: 1
votes: 0


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

7:55 pm on Jan 30, 2009 (gmt 0)

Senior Member

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Mar 31, 2002
votes: 0

Your syntax specifies an external redirect, telling the client to ask again for the page at the new URL. You want an internal rewrite, which only changes the filepath associated with the requested URL. Further, it will be necessary to take steps to prevent recursion (to prevent "looping" and rewriting <studenten>.example.com/x.html to /<studenten>/x.html and then to /<studenten>/<studenten>/x.html, and then to /<studenten>/<studenten>/<studenten>/x.html, etc. This involves "tagging" your '/users' directories and adding an extra line of code:

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]

Here, a request for the URL "michele.example.com/auto.xyz" or "www.michele.example.com/auto.xyz" will be rewritten to the filepath "/users/michele/auto.xyz".

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".