homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

How to invisible indirect

5+ Year Member

Msg#: 3838371 posted 5:35 pm on Jan 30, 2009 (gmt 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



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

Msg#: 3838371 posted 7:55 pm on Jan 30, 2009 (gmt 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".


Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved