0

我试图找出一种在循环中重定向到不同 url 的方法。

例如......我有这个网址:

http://mydomain.com/subfolder/1  

我需要上面 url 末尾的 1 在循环中每次增加 1

所以它会这样做:

redirect here - http://mydomain.com/subfolder/1
redirect here - http://mydomain.com/subfolder/2
redirect here - http://mydomain.com/subfolder/3

所以它会去:

while (a < 100) {
header("Location: http://mydomain.com/subfolder/" Increment number here );
}

我怎样才能在 PHP 中做到这一点?

4

4 回答 4

0

您可以在每次访问脚本时检索页面,如下所示:

$lastpage = basename($_SERVER[REQUEST_URI])

然后增加它并在需要时重定向到下一页。

干杯,

于 2013-02-13T11:33:38.920 回答
0

如果您有一个重写规则/subfolder/(\d+)script.php?index=$1那么您可以尝试:

header("Location: /subfolder/" . ($_GET["index"] + 1));

;-)

于 2013-02-13T11:36:09.910 回答
-1

您可以使用

<?php
    $myvar = Array();
    for ($i = 1; $i <= 5; ++$i) {
        echo $myvar[$i] = 'header("Location: http://mydomain.com/subfolder/'.$i.'")';
    }
?>
于 2013-02-13T11:42:03.443 回答
-2

如果 $a 是你的增量 no 那么

$a=1;
 while ($a < 100) {
  header("Location: http://mydomain.com/subfolder/'".$a."'");
   $a++;
  }
于 2013-02-13T11:33:02.580 回答