我在搜索链接时遇到了麻烦。 我的网站中有关键字,它们像这样链接到搜索页面:
keywords.php?search=news_title
那样很好。
但是当我用htaccess添加seo_url时:
在news_detail.php中添加链接
keywords/search/news_title/
AND
htaccess文件中的链接
RewriteRule ^keywords/search/([a-zA-Z0-9_-]+)/$ keywords.php?search=$1 [NC,L]
我尝试过[NC],[L]很好。
当我单击链接时,请保持重定向到index.php。
这是我的搜索查询:
if(isset($_GET["search"]) && !empty(htmlspecialchars($_GET["search"]))){
$search = $_GET['search'];
$sech = htmlspecialchars($search);
$search = test_input($sech);
$stmt =$pdo->prepare("SELECT * FROM posts WHERE title LIKE :search OR subject LIKE :search OR descriptions LIKE :search OR keywords LIKE :search");
$stmt->bindValue(":search","%".$search."%", PDO::PARAM_STR);
if($stmt->execute()){
if($stmt->rowCount() > 0){
while($row = $stmt->fetch(PDO::FETCH_ASSOC)){?>
<div class="search_detail">
<a href="<?php echo test_input($row['news_url']);?>/">
<div class="image"><img src="images/posts/<?php echo test_input($row['img']);?>" height="100" width="98%"/></div>
<div class="title"><h1><?php echo test_input($row['title']);?></h1></div>
<div class="spot"><p><?php echo test_input($row['subject']);?></p></div>
</a>
</div>
<?php
}
}else{
echo "Aradığınız kelimeyi bulamadık özür dileriz";
header("Refresh: 2; url=".$c."error.php");
exit();
}
}
unset($stmt);
}else{
header("Location: ".$c."index.php");
exit();
}
这是我的htaccess:
Options +FollowSymLinks RewriteEngine On
RewriteRule ^home index.php [NC,L]
RewriteRule ^contact/$ contact.php [NC,L]
RewriteRule ^forgot/$ hml.php [L]
RewriteRule ^search/$ search.php [NC,L]
RewriteRule ^keywords/search/([a-zA-Z0-9_-]+)/$ keywords.php?search=$1 [NC,L]
RewriteRule ^kariyer-basvuru/ ik.php [NC,L] RewriteRule ^feed/$ rss.php [NC,L]
RewriteRule ^sitemap.xml$ sitemap.php [NC,L]
RewriteRule ^user/$ login.php [NC,L]
RewriteRule ^change-password/$ resetpass.php [NC,L]
RewriteRule ^Upanel/page/(.*)$ Upanel/?page=$1 [L]
RewriteRule ^Upanel/page_sale/(.*)/$ Upanel/account.php?page_sale=$1 [L]
RewriteRule ^Upanel/del-ilan/(.*)/$ Upanel/delil.php?id=$1 [L]
RewriteRule ^Upanel/Store-edit/(.*)/$ Upanel/Sedit.php?store_id=$1 [L]
RewriteRule ^Upanel/del-store/(.*)/$ Upanel/Sdel.php?store_id=$1 [L]
RewriteRule ^Upanel/del-comment/(.*)/$ Upanel/Cdel.php?id=$1 [L]
RewriteRule ^Upanel/opens/$ Upanel/opens.php [L]
RewriteRule ^Upanel/editadds/(.*)/$ Upanel/Pedit.php?id=$1 [L]
RewriteRule ^Upanel/ilanv/$ Upanel/ilanv.php [L]
RewriteRule ^Upanel/profil-duzenle/(.*)/$ Upanel/profile.php?id=$1 [L]
RewriteRule ^Upanel/$ Upanel/index.php [NC,L]
RewriteRule ^stores/(.*)/([a-zA-Z0-9_-]+)$ store.php?s=$1 [L]
RewriteRule ^stores/$ isletmeler.php [NC,L]
RewriteRule ^([a-zA-Z0-9_-]+)/$ detail.php?p=$1 [NC,L]
RewriteRule ^category/([a-zA-Z0-9_-]+)/$ categories.php?q=$1 [NC,L]
我在标头中的php文件中使用rewcond标签。