Forum Moderators: phranque

Message Too Old, No Replies

htaccess code transparent redirect

I'm a newbie needing htaccess code help

         

chaser123

8:24 pm on Sep 7, 2009 (gmt 0)

10+ Year Member



I have domain.com working and have subdomain called test01.domain.com for testing my site in a different look and style. What I want to do is redirect users from domain.com to test01.domain.com transparently so the users do not know they are moved to the new location.

domain.com to test01.domain.com transparently so that the users address bar remains listed as domain.com

I have searched the forums and read numerous other posts without coming up with the answer. I'm sure a big part of the problem is my inexperience, so I appreciate all the help and support.

chaser123

8:29 pm on Sep 7, 2009 (gmt 0)

10+ Year Member



I thought I should add what I have used so far in the domain.com .htaccess file. This seems to handle the redirect ok, but the address bar changes to the test01.domain.com address and I don't know how to mask it so the address bar remains as domain.com

RewriteEngine On
RewriteCond %{HTTP_HOST} ^domain.com$ [NC]
RewriteRule ^(.*)$ [test01.domain.com...] [R=301,L]

g1smd

10:43 pm on Sep 7, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



You have used a "redirect".

What you need is a "rewrite".

One of those omits the domain name and the R=301 bit at the very least.

The target will be an internal filepath on the server, not a new URL.

The difference between a redirect and a rewrite, and between a URL used out on the web and a filepath used inside the server, is also crucial.

jdMorgan

3:38 pm on Sep 8, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



An internal rewrite will refer to the *filepath* to the 'test01' site/pages/resources. This filepath may or may not be 'visible' in the context of requests to the 'main site' -- This depends on how your 'test01' subdomain is defined/configured on your server.

If the files for 'test01' are stored in a subdirectory below the 'main directory' for "example.com", then it's a simple matter of adding that subdirectory path to the requested path (while preventing a loop). For example, if the resources for example.com are stored in the server filespace at /var/www/html/example/ and the resources for test01.example.com are stored in the server filespace at /var/www/html/example/test01/ then something like this will likely work:


RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteCond $1 !^site01/
RewriteRule ^(.*)$ /site01/$1 [L]

However, if the test01 files are stored elsewhere, then look into creating 'symbolic links' in your server's filesystem (this may not be an option on shared hosting). Otherwise, consider copying and renaming the directories.

Jim

chaser123

5:03 pm on Sep 9, 2009 (gmt 0)

10+ Year Member



Thanks so much for the help. The test01 files are stored in another location, so I think I will just copy and rename as you suggested. Thanks again.