Чтобы проверить, будет ли полезен новый дизайн, мы проводим A / B-тестирование. Однако дизайн объединяет большое количество файлов, поэтому нам не нужно постоянно их перемещать.
Можно ли использовать mod_rewrite, чтобы замаскировать тот факт, что мы переместили оба в их собственные подкаталоги?
Другими словами, кто-то посещает http://www.ourdomain.com/ и они видят дизайн, расположенный в "public_html / old /" или "public_html / new /", в зависимости от того, что мы установили для отображения в .htaccess. Однако они никогда не знают, что дизайны находятся в поддиректориях.
Хорошо! После того, как вы переместили оба в их подкаталоги, вы можете сделать что-то вроде этого:
<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
Случайный выбор намного сложнее, и я мог что-то пропустить ... дайте мне знать, если он сломается.