【发布时间】:2014-07-14 13:19:47
【问题描述】:
我想尝试布局,看看哪些有效,哪些无效。我不想对所有流量都这样做,以防万一出现问题。为此,我想将部分流量重定向到单独的文件。我想使用 .htaccess 来做到这一点。我的第一次尝试是重定向 IP 地址以 1 或 2 结尾的人以获得新布局。我想动态设置 DirectoryIndex 来做到这一点。
这就是我所拥有的:
Options +FollowSymlinks
RewriteEngine On
RewriteBase /
#split 20% of the traffic to go to the alternative layout
RewriteCond %{REMOTE_ADDR} "*(1|2)$"
RewriteRule .? - [S=4]
RewriteRule ^fb/([^/]+) /fb.php?id=$1 [nc]
RewriteRule ^classic /?layout=classic [QSA,nc]
RewriteRule ^thumbs /?layout=thumbs [QSA,nc]
DirectoryIndex 3.php
#the rest of the traffic goes to the default layout
RewriteCond %{REMOTE_ADDR} "!(1|2)$"
RewriteRule .? - [S=1]
DirectoryIndex index.php index.html
AddDefaultCharset utf-8
但这并没有达到预期的效果,如果我能在 .htaccess 中有这个伪代码,我会很高兴:
if %{REMOTE_ADDR} matches "*(1|2)$"
DirectoryIndex 3.php
else
DirectoryIndex index.php
【问题讨论】:
标签: apache .htaccess mod-rewrite redirect