PHP搜索表不适用于.htaccess



我的搜索乡村表格有代码:

 <form name="form_search" id="form_search" class="form1" method="get" action="country/search"><div class="row">
<div class="col-sm-4 col-md-7">
<label>Select country</label>
<div class="select1_inner">
<div class="form-group">
<select class="select2 select" style="width: 100%" name="q" id="q">
<?php
$sql = "SELECT * FROM country";
$query = $conn->query($sql);
while ($row = $query->fetch_assoc()) :
$country_name=$row['country_name']; 
?>
<option value=<?php echo $country_name?>><?php echo $country_name?></option>
<?php endwhile;?> 
</select>
</div>
</div>
</div>

在前端url将显示:http://example.com/country/search?q=参见表

,但我会在后端http://example.com/page.php?module = search&amp;Id1 = $ 1

url重定向到真实目录

使用.htaccess

 RewriteEngine On
 Options -Indexes
 rewriteRule ^country/search$  page.php?module=search&id1=$1  [L]

但这不起作用,我无法获得值q参数

请帮助我如何配置此表格

谢谢。

您应该使用 RewriteCond backeference:

RewriteCond %{QUERY_STRING} q=([^&]*)
RewriteRule ^country/search$ page.php?module=search&id1=%1 [R=301,L]

第1行:测试是否包含q={any_characters}

的查询字符串

第2行:如果URL为 country/search,则重定向到page.php?module=search&id1={any_characters}永久

最新更新