我在我的網站上有一個搜索引擎,SERP的網址是search/QUERY/1/
。搜索框到高級網址
如何製作一個HTML搜索框來填寫我的URL的QUERY
部分?
它不能真正使用PHP,但它可以使用JavaScript,如果它必須。使用jQuery
我在我的網站上有一個搜索引擎,SERP的網址是search/QUERY/1/
。搜索框到高級網址
如何製作一個HTML搜索框來填寫我的URL的QUERY
部分?
它不能真正使用PHP,但它可以使用JavaScript,如果它必須。使用jQuery
HTML:
<form action="index.php" method="post">
<input type="text" name="word" />
<button type="submit">Search</button>
</form>
的index.php:
<?PHP
if(isset($_POST['word']))
{
header('location: /search/' . $_POST['word'] . '/');
exit();
}
//Other index.php codes
?>
是的,你可以,但你必須把它放在index.php的頂部,爲了更好的優化,把:exit(); affter標題行。 – 2011-04-15 11:40:05
編輯我的答案,使用此 – 2011-04-15 11:44:41
:
$('#search_button').click(function() {
var query = encodeURIComponent($('#search_query').val());
var searchurl = 'http://www.mysite.com/search/{query}/1/';
var newurl = searchurl.replace('{query}',query);
alert(newurl);
// $(location).attr('href',newurl);
});
<input type="text" id="search_query">
<input type="button" id="search_button" value="Search">
你將不得不使用Java腳本,這就是爲什麼它不是一個真正鼓勵值得的IMO實踐。 – 2011-04-14 22:40:23
這裏有一個很好的重複:[尼斯搜索URL](http://stackoverflow.com/questions/4890272/nice-search-urls) – 2011-04-14 22:43:21