需要帮助使用mod_rewrite对不同的dirs中的2个devise进行分割testing

为了testing新devise是否有用,我们正在对其进行A / Btesting。 但是,这个devise集成了大量的文件,所以我们不想不停地移动它们。

有没有可能使用mod_rewrite来掩盖事实,我们已经移动到他们自己的子代?

换句话说,有人访问http://www.ourdomain.com/ ,他们看到devise位于“public_html / old /”或“public_html / new /”取决于我们已经设置在.htaccess中显示。 但是,他们从来不知道devise是在细分市场。

好! 在你将两者都转移到他们的subdirs后,你可以做这样的事情:

<VirtualHost *:80> ServerName example.com # .. any other needed config, logging, etc # Yes, you'll leave this at the parent directory.. DocumentRoot /var/www/public_html <Directory /var/www/public_html> Order Allow,Deny Allow from all RewriteEngine On # Let's prevent any rewrite of anything starting with new or old, # to head off potential internal redirect loops from pass-thrus.. RewriteRule ^(new|old) - [L] # Here's where we'll handle the logic. # This will vary the page based on IP address. # If the user is in the 10.0.0.0/8 address range... RewriteCond %{REMOTE_ADDR} ^10\..*$ # ...then we'll give them the new page. RewriteRule ^(.*)$ new/$1 [L] # Otherwise, we'll give them the old page. RewriteRule ^(.*)$ old/$1 [L] </Directory> </VirtualHost> 

你可以触发任何mod_rewrite可以看到的东西。 对于cookie,交换这个在Here's where we'll handle the logic. 以上:

 RewriteCond %{HTTP_COOKIE} newsite=true # Client sent a cookie with "newsite=true" RewriteRule ^(.*)$ new/$1 [L] # No matching cookie, give them the old site RewriteRule ^(.*)$ old/$1 [L] 

GET请求查询参数:

 RewriteCond %{QUERY_STRING} newsite=1 # Client sent /path/to/page?newsite=1 - give them the new one RewriteRule ^(.*)$ new/$1 [L] # Fall back to the old one RewriteRule ^(.*)$ old/$1 [L] 

或两者兼而有之

 RewriteCond %{QUERY_STRING} newsite=1 [OR] RewriteCond %{HTTP_COOKIE} newsite=true RewriteRule ^(.*)$ new/$1 [L] RewriteRule ^(.*)$ old/$1 [L] 

随机..

 # We'll use a cookie to mark a client with the backend they've been stuck to, # so they they don't get fed /index.html from /old then /images/something.jpg # from /new. Handle that first.. RewriteCond %{HTTP_COOKIE} sitevers=(old|new) RewriteRule ^(.*)$ %1/$1 [L] # They didn't have a cookie, let's give them a random backend. # Define our mapping file, we'll set this up in a minute.. RewriteMap siteversions rnd:/var/www/map.txt # Since we need to use the random response twice (for the directory and the # cookie), let's evaluate the map once and store the return: RewriteCond ${siteversions:dirs} ^(.*)$ # ..then, use what we just stored to both select the directory to use to # respond to this request, as well as to set a cookie for subsequent requests. RewriteRule ^(.*)$ %1/$1 [L,CO=sitevers:%1:.example.com:0] 

并设置这些内容的/var/www/map.txt文件:

 dirs new|old 

随机是复杂得多,我可能已经错过了一些东西。让我知道如果它打破。