我改变了这个网址 http://localhost/rozgar/job.php?search=Testing%201&id=43 对此 http://localhost/rozgar/job/Testing%201/43 使用.htaccess
RewriteRule ^job/([A-Za-z]+) job.php?id=$1&search=$2
链接工作正常,但php没有从数据库加载数据,它显示我错误..
<?php
include "inc/db.php";
$id = @$_GET['id'];
$search = @$_GET['search'];
session_start();
$email = @$_SESSION['email'];
$id=@$_GET['id'];
$query="select * from company,jobs where company.id = jobs.company_id AND jobs.id = '$id'";
$run=mysqli_query($db,$query);
while ($row = mysqli_fetch_assoc($run)) {
}
答案 0 :(得分:0)
你必须尝试这个规则。您已经为搜索字段传递了值,但您也传递了id的值,如(0-9)。那么你的htaccess规则如下所示。
RewriteRule ^job/([A-Za-z-]+)/([0-9]+) job.php?search=$1&id=$2
在此之后,您可以将其删除。
http://localhost/rozgar/job/testing/43
请记住,有一件事你不应该在url中传递值,其中有“测试002”这样的空间你的htaccess规则中断。为此,您必须将空格转换为下划线。
答案 1 :(得分:0)
只需像这样创建.htaccess
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^([^/]+)/?$ $1.php [L]
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/?$ job.php?id=$1&search=$2 [L,QSA]
现在在job.php中获取get变量