내 사이트에 검색 엔진이 있으며 SERP의 URL은 search/QUERY/1/
입니다.고급 검색 창에서 검색 상자
내 URL의 QUERY
섹션을 채우기 위해 HTML 검색 상자를 만들려면 어떻게해야합니까?
PHP를 실제로 사용할 수는 없지만 꼭해야한다면 javascript를 사용할 수 있습니다. jQuery를 사용하여
내 사이트에 검색 엔진이 있으며 SERP의 URL은 search/QUERY/1/
입니다.고급 검색 창에서 검색 상자
내 URL의 QUERY
섹션을 채우기 위해 HTML 검색 상자를 만들려면 어떻게해야합니까?
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 위에 놓아야하며 최적화를 위해 put (exit); 어 테이터 헤더 행. –
내 답변 편집, 사용 –
:
$('#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">
당신은 자바를 사용하는 것 스크립트, 그래서 정말 격려 - 가치 연습 IMO 아니에요. –
다음은 좋은 복제본입니다. [멋진 검색 URL] (http://stackoverflow.com/questions/4890272/nice-search-urls) –