0

我想使用我的 .htaccess 以下列方式重写我的 URL:

 http://localhost/admin/variable1/variable2/variable3/ (etc)

至:

 <?php
 $var1 = $_GET['variable1'];
 $var2 = $_GET['variable2'];
 $var3 = $_GET['variable3'];
 ?>

此外,它应该适用于 0、1、2、3、4 和更多变量。有谁知道如何做到这一点?

谢谢!

4

1 回答 1

0

您可以这样做:首先创建一个.htaccess文件,“假设您使用的是 apache”。

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ index.php?r=$1 [L]
</IfModule>

PHP 代码将是这样的:

<?php

    $route = isset($_GET["r"]) ? $_GET["r"] : "/";
    var_dump($route, explode("/", $route));

然后,当您访问以下 URL 时:

http://127.0.0.1/example/a/b/c/d/e/f

输出:

string 'a/b/c/d/e/f' (length=11)
array (size=6)
  0 => string 'a' (length=1)
  1 => string 'b' (length=1)
  2 => string 'c' (length=1)
  3 => string 'd' (length=1)
  4 => string 'e' (length=1)
  5 => string 'f' (length=1)
于 2013-03-09T15:09:37.163 回答