繁体   English   中英

URL重写和GET参数

[英]URL rewrite and GET parameter

我仅对index.php使用htaccess url重写,并使用PHP捕获GET参数。 当尝试不同的参数时,我的网站在某些参数上给出了404错误,我觉得很奇怪。 但是,以下是详细信息:

htaccess

RewriteRule ^([^/index.php]*)$ /index.php?company=$1 [L]

index.php

<?php
$name = 'specialpromo';

if(isset($_GET['company'])) {
    include 'include/dbconfig.php';  

    // Create connection
    $conn = mysqli_connect($servername, $username, $password);

    // Check connection
    if (!$conn) {
        $errmsg = "Connection error";
    } else {
        if(!(mysqli_select_db($conn,$dbname))){
            $errmsg = "Database error";
        } else {
            $sql_comp = $conn->prepare("select a.* 
            from company a
            where a.code = ?");
            $sql_comp->bind_param('s', $_GET['company']);
            $sql_comp->execute();
            $rs_comp =  $sql_comp->get_result() or die('Error, query failed<br />');

            $numrow_comp = mysqli_num_rows($rs_comp);

            if ($numrow_comp==1){
                if($row_comp = mysqli_fetch_assoc($rs_comp)){
                    $name = $row_comp['name'];
                }
            }

            mysqli_free_result($rs_comp);
        }
        mysqli_close ($conn);
    }
}
?>

请尝试使用以下网址,因为这两个值均不在我的数据库中,它们给出了奇怪的结果。

  1. https://shop.specialpromo.asia/ddd将返回错误404
  2. https://shop.specialpromo.asia/aaa将加载正常,尽管未找到结果
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*) index.php?company=$1 [L]

第1行:如果请求uri与任何现有目录都不匹配

第2行:如果请求uri与任何现有文件都不匹配

第3行:然后对于每个请求uri,重写为index.php?company=$1$1是对正则表达式(.*)的反向引用(.*)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM