Forum Moderators: phranque
~/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.
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
RewriteEngine onRewriteCond %{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?
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]
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