Forum Moderators: phranque
I have a website let's say www.test.nl and I want it redirected to www.test.com but i want the url www.test.nl to stay in the address bar.
What do I need to put in the htaccess file to get this working?
Anyone?
Welcome to WebmasterWorld [webmasterworld.com]!
If both domains are pointed to same 'account' on one server, you can use mod_rewrite to do internal redirects when needed.
If they are on different servers, you can either change the DNS to point both domains to the same server and proceed as above, or you can display the pages from the 'real' site inside an iframe on the 'alias' site. However, that approach may break some of your navigation, and so should be tested thoroughly. It may only work for MSIE browsers, too.
Introduction to mod_rewrite [webmasterworld.com]
Jim
Not really off-topic for the original question... :)
There are two ways to modify requested URIs using mod_rewrite: internal rewrites, and external redirects.
Internal rewrites are 'silent', that is, no sign of the change is visible to the user. Rewrites can only be done 'inside' the server -- only the filename associated with the URL is changed, not the domain name. (Note that the filename does not need to have anything in common at all with the URL-path - we're just used to them being the same most of the time.)
Example:
RewriteRule ^foo\.html$ /bar.html [L]
Here, if a client requests the page (file) "foo.html", the server sends the content from the file "bar.html", and gives no indication at all that it used "bar.html" instead of "foo.html" for the filename.
---
External redirects are needed in order to change anything within the 'domain', such as changing www.example.org to www.example.com. For an external redirect, the server does not send the requested content to the client (browser or spider). Rather, it sends a short message saying, "301-Moved Permanently" using an HTTP status response header. The server may also include the new URL for the requested content (modern servers always do).
This 301 response *ends* the current HTTP transaction which was initiated by the client. However, the client browser or spider usually takes the new URL and immediately re-requests the content from the new address. Note that this is a completely-new HTTP transaction. (This is not obvious unless you study HTTP [w3.org], and not remembering this fact can result in massive confusion about many redirection and server security issues).
The address seen by the user will change as a result of the 301 server response, before the browser makes the new request.
External redirects are also used to let users and search engine spiders know that a page has been replaced, even if the domain does not change.
Examples:
# Redirect example.org to example.com (Both domains point to this server)
RewriteCond {HTTP_HOST} ^www\.example\.org
RewriteRule (.*) http:www.example.com/$1 [R=301,L]# Redirect old.html page to new.html, and let the user see the redirect.
RewriteRule ^old\.html$ http:www.example.com/new.html [R=301,L]
Jim