Forum Moderators: phranque

Message Too Old, No Replies

how to create a root-level testing section of a site?

         

zollerwagner

10:05 pm on Mar 20, 2004 (gmt 0)

10+ Year Member



I need to set up a test site so I can test changes I want to make before they go live.

I used to do this is a subdirectory, but now I've got pages that require absolute reference to root, so that no longer works.

I'm thinking I could create subdomain, like: test.mydomain.com

Will that work?

How do others handle this?

bill

7:32 am on Mar 21, 2004 (gmt 0)

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



A subdomain or even a folder will generally work if you password protect it.

zollerwagner

8:48 pm on Mar 23, 2004 (gmt 0)

10+ Year Member



Thanks, Bill. I'll try the subdomain. The folder doesn't work because the page references in the site are absolute, like this:
/ssi/header.ssi
/images/image01.jpg

If you put the whole site in a folder, the browser looks for the included file, image, or whatever starting from the root directory rather than starting from the folder. There may be a way around that using a rewrite, but I haven't figured it out yet.

pleeker

8:55 pm on Mar 23, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'm thinking I could create subdomain, like: test.mydomain.com

That's how we do it. Well, not always with "test", but some hidden word no nosy-body would ever find. :)

zollerwagner

9:30 pm on Mar 23, 2004 (gmt 0)

10+ Year Member



It's great to have confirmation that this will work. Thanks, Pleeker!

bill

2:33 am on Mar 24, 2004 (gmt 0)

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



Another thing you could possibly do if your host allows it is to add another separate account, with its own domain.

jdMorgan

2:47 am on Mar 24, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The fact that you have a test subdomain and that it resides in a subdirectory won't interfere with your absolute URLs because the same rewrites you use to 'map' the subdomain to the subdirectory will be invoked for any URL, thus making it look like the files in the subdirectory *are* at the root of the subdomain...

Works for me with no problems. The only problem you may have is if you use canonical URLs, that is, links like <a href="http://www.example.com/images/image01.jpg"> -- Obviously, those would have to be changed to point to your test subdomain.

The beauty of URL rewriting, whether accomplished by scripts, mod_rewrite, or ISAPI rewrite, is that URLs and filepaths need not have *any* fixed relationships.

Jim

P.S. Don't forget to put an appropriate robots.txt file in that "subdomain root" subdirectory!

zollerwagner

4:36 am on Mar 24, 2004 (gmt 0)

10+ Year Member



Hello, jdMorgan! I'm not sure what background situation you're referring to when you write:
jdMorgan said: the same rewrites you use to 'map' the subdomain to the subdirectory will be invoked for any URL...

You use rewrites and a folder that is actually in the root directory? Interesting idea.

What's the purpose? Is that so you can do FTP without having to go below the orginal root level? I've had trouble with that, ended up setting up two different FTP connections for each site.

Would something similar work with files you want to keep "below root" for security purposes? That strikes me as risky, but maybe it's not.

Also, thanks for the heads up on canonicals. I probably did have a couple of those for no good reason!

jdMorgan

5:32 am on Mar 24, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



My purpose is that I rent web space, and so have access only to my Web space and .htaccess. So I can't get into httpd.conf and set up a separate virtual server for testing. So, I just use the space I have, and make it look like two different subdomains. If you do have access to httpd.conf, then don't bother with this technique -- it's much simpler to do it 'the right way' if you can set up an entirely different space for testing.

I don't know a good short way to explain it, except by example. I use the following code in my Web root .htaccess to support a test subdomain by mapping it to a subdirectory in my single "account."


# Redirect test subdomain to subdirectory /test/
RewriteCond %{HTTP_HOST} ^test\.example\.com
RewriteCond %{REQUEST_URI} !^/images/
RewriteRule (.*) /test/$1 [L]

That, plus adding an "A record" in my DNS zone file to point test.example.com to my IP address is all that's required. I can then put files into www.example.com/test/ using FTP and it looks and acts like the Web root directory of test.example.com from an HTTP viewpoint. Note that I 'share' my images between my 'test' subdomain and my 'real' domain and www subdomain. I just do this to avoid having to have two copies of my stock images and logos on the server, since they hardly ever change. If I do need to mess around with those images, I can always just comment-out the RewriteCond and create another /images subdirectory under /test.

If you want to be 'symmetrical' about it, you could map your domain and your www subdomain to a subdirectory named 'production' and then go 'live' with the new stuff by simply renaming the 'test' subdirectory to 'production' whenever you're ready. Basically, rename or copy 'production' to 'backup', then rename 'test' to 'production.' If you use a shell script to do it, the switch-over is practically instantaneous.

The only really tricky part is if you want to do authentication. In that case, it's much easier if you do the subdomain->subdirectory rewriting in httpd.conf. This is because of the order in which Apache does things; It will do rewrites in httpd.conf, then do authentication, and then process rewrites in .htaccess. So, your test.example.com site password logins can get complicated (OK, messed-up) if you do the rewrite in .htaccess.

There are two work-arounds to this. The first is to not support authenticated subdirectories in your 'test' subdomain; Instead, you just use a RewriteCond like the one I used for /images/ above to 'share' all authenticated subdirectories between all the subdomains. The problem with this is that you then don't have a copy of the authenticated subdirectories for test purposes, so you have test those subdirectories on the 'live' site.

The other work-around is to put all your authentication code in .htaccess in the true Web-root directory or in httpd.conf. In that case, you'll need a separate section in that code for the subdomain-support subdirectory or subdirectories.

As in most things, mod_rewrite gives a lot of flexibility, but at the cost of complexity. Once you get used to the way this technique works, though, it's not so bad.

I hope that explains it somewhat clearly. :)

Jim

zollerwagner

9:33 am on Mar 24, 2004 (gmt 0)

10+ Year Member



Yes, that does help. Thanks!

I'm a little embarrassed to admit that when I finally tried this out, I didn't need to do anything special. I thought I was going to have to go through a process of writing redirects and so forth as you described.

It appears that because my Web host uses cpanel, I can just create a new subdomain (like subdomain.mydomain.com) in cpanel. Then if I create a folder called "subdomain" in the main site's root folder, it automatically redirects to that folder. It's easier than making Jello.