1

.htaccess

RewriteEngine On
RewriteRule ^([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/$ http://localhost/website/sale/phones/index.php?type=$1&location=$2
RewriteRule ^([A-Za-z0-9-]+)/$                 http://localhost/website/sale/phones/index.php?type=$1

我有这样设置的链接

if (!isset($_GET['type'])) {
    $query = "SELECT type, url FROM {$phones}";

    $result = mysql_query($query);

    while($phone = mysql_fetch_assoc($result)) {
        echo '<li><a href="'. $phone['url'] .'/">'. $phone['type'] .'</a></li>';
    }
} else {
    $query = "SELECT location, url FROM locationstwo LIMIT 100";

    $result = mysql_query($query);

    while($location = mysql_fetch_assoc($result)) {
        echo '<li><a href='. $_GET['type'] .'/'. $location['url'] .'/>'. $location['location'] .'</a></li>';
    }   
}

?>

url 根据需要在左下角显示为 localhost/website/sale/phones/phonetype/location/

但是一旦点击链接,地址栏就会出现 ? 变量

localhost/website/sale/phones/index.php?type=phone-type&location=location 当我真正想要的是 localhost/website/sale/phones/phone-type/location/

它与.htaccess有关吗?

也就是说,当使用 /phone-type/location/ 显式键入时,它会传递参数,因此 htaccess 正在工作,但地址栏仅使用 ?varialbe 显示它们。

我怎样才能解决这个问题?谢谢。

4

1 回答 1

1

这是由于不正确的重写规则造成的。确保使用没有域的路径作为目标。用这个替换你的代码:

RewriteRule ^([\w-]+)/([\w-]+)/?$ /website/sale/phones/index.php?type=$1&location=$2 [L,QSA]
RewriteRule ^([\w-]+)/?$ /website/sale/phones/index.php?type=$1 [L,QSA]
于 2013-09-26T11:18:51.887 回答