如何使用正则表达式选项将我的一个页面重定向到另一个网站的随机页面?

我想将页面重定向到example.net/path路径1 到 5127 之间的随机数的位置。

例如: http://www.example.com/bin ----重定向到----> https://example.net/3417

然后我想将每个重定向的页码增加 10,如本例中从 1000 路径开始:

http://www.example.com/bin ----重定向到----> https://example.net/1010 http://www.example.com/bin ----重定向到----> https://example.net/1020 http://www.example.com/bin ----重定向到----> https://example.net/1030

等等,据我所知,这可以通过htaccess或简单的php 页面来完成。


qq_花开花谢_0
浏览 82回答 1
1回答

翻翻过去那场雪

这将实现你所追求的。它利用 php 会话来跟踪您要重定向到的号码。<?phpsession_start();// Check whether you've already redirected a user and if not, create a random number between min and max$MIN = 1;$MAX = 5127;$rand = $_SESSION['last_redirect'] ?? rand($MIN,$MAX);// Check whether you're within 10 of the maximum or not and if so, generate a new random number, if not add 10 on.$rand = ($rand <= ($MAX-10)) ? $rand+10 : rand($MIN,$MAX);// Store the value in a session for the next time the page is loaded$_SESSION['last_redirect'] = $rand;// Redirect ...$redirect_to = 'https://example.net/'.$rand;header("refresh:0; url=$redirect_to");?>这是一个实际的例子:1) 导航到 php 页面:2) 重定向到 example.net 并附加一个随机数:3) 导航回 php 页面(第 1 步)并再次重定向但增加 10:这将一直增加 10,直到您清除 php 页面的浏览历史记录(或取消设置会话变量),或者直到达到您指定的最大数量。一旦您在最大值的 10 以内,它就会生成一个新的随机数并将您重定向到该随机数。
打开App,查看更多内容
随时随地看视频慕课网APP