Forum Moderators: phranque

Message Too Old, No Replies

Proper Method of separating Test & Production directories?

.htaccess mod_rewrite config and directory structure

         

bmambo

12:21 am on Dec 20, 2004 (gmt 0)

10+ Year Member



My small Mambo-based site is hosted at an ISP and operates successfully today. However, I am doing an upgrade and want to end up with two subdirectories:

~/www/mambo/ (the production site, currently exists)

and

~/www/mambo2/ (a proposed test site for working on upgrades)

In directory /www, I have the following .htaccess code successfully redirect general web requests to the mambo directory:


RewriteEngine On
RewriteCond %{REQUEST_URI}!^/mambo/
RewriteRule (.*) /mambo/$1 [L]

What I'd like to do is redirect requests as follows:

[mysite.com...] --> goes to the /www/mambo directory

and also

[mysite.com...] --> goes to the /www/mambo2 directory

Then I can more or less silently work on mambo2 until it's ready and then simply rename the directories to put it all into production. Here are my questions:

1. Is this a reasonable method of separating production from test within a single web site? If not, what's the most appropriate way of doing it?

2. If the production-test structure I've described is reasonable, how should I configure the .htaccess files to implement this? I am thinking of something like this:


RewriteEngine On
RewriteCond %{REQUEST_URI}!^/mambo/
RewriteRule (.*) /mambo/$1 [L]
RewriteEngine On
RewriteCond %{REQUEST_URI} /mambo2/
RewriteRule (.*) /mambo2/$1 [L]

Obviously I am new and this and I am therefore reluctant to try out code on my live site unless I get some advice from those who know.

jdMorgan

3:56 am on Dec 20, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I don't know about other webmasters' preferences, but I prefer to use subdomains, as in:

example.com -------> www.example.com (301 redirect) 
www.example.com ---> htdocs/www/ (internal rewrite)
test.example.com --> htdocs/test/ (internal rewrite)

As long as all "test" URLs are rewritten the same way, there is no danger of getting confused about directory levels and such between the test environment and the production environment.

Jim

bmambo

7:56 pm on Dec 25, 2004 (gmt 0)

10+ Year Member



That's a really good idea, and much simpler than my overly complex notions. I've attempted to produce an htaccess that implements this, having both "prod" and "beta" directories. Subdomain "beta.site.com" is redirected to /beta. Here is the htaccess code.

RewriteEngine on

RewriteCond %{HTTP_HOST} ^beta.site.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.beta.site.com$
RewriteRule ^(.*)$ http://site.com/beta/$1 [R=301,L]

RewriteCond %{HTTP_HOST} ^site.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.site.com$
RewriteRule ^(.*)$ http://site.com/prod/$1 [R=301,L]

However, this doesn't seem to work. "www.site.com" and "site.com" work, but "beta.site.com" results in "Redirection limit for this URL exceeded." What the heck am I missing here? Did I not direct each URL to the correct directory?

jdMorgan

11:09 pm on Dec 25, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



> What the heck am I missing here?

You need to exclude requests for the subdirectories /beta and /test from being rewritten to avoid a redirection loop. Also, there's no reason to use an external redirect. For eaxmple, add a RewriteCond to check for "%{REQUEST_URI} NOT /beta" and use the internal rewrite form of RewriteRule:


RewriteCond %{HTTP_HOST} ^(www\.)?beta\.site\.com
RewriteCond %{REQUEST_URI} !^/beta
RewriteRule (.*) /beta/$1 [L]

Note that the first RewriteCond now accepts either www- or non-www hosts, the literal periods are now escaped, and the end-anchor has been removed to prevent problems if a user-aqent appends a port number, i.e. beta.site.com:80/

It's also not necessary to anchor the ^(.*)$ pattern, since ".*" is "greedy" and will match as much of the URL as possible, even without being anchored.

Similar changes to your other rule are needed, I just showed your first case above.

Jim