2011-04-14 8 views
1

내 사이트에 검색 엔진이 있으며 SERP의 URL은 search/QUERY/1/입니다.고급 검색 창에서 검색 상자

내 URL의 QUERY 섹션을 채우기 위해 HTML 검색 상자를 만들려면 어떻게해야합니까?

PHP를 실제로 사용할 수는 없지만 꼭해야한다면 javascript를 사용할 수 있습니다. jQuery를 사용하여

+0

당신은 자바를 사용하는 것 스크립트, 그래서 정말 격려 - 가치 연습 IMO 아니에요. –

+0

다음은 좋은 복제본입니다. [멋진 검색 URL] (http://stackoverflow.com/questions/4890272/nice-search-urls) –

답변

1

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 
?> 
+0

그래, 할 수는 있어도 index.php 위에 놓아야하며 최적화를 위해 put (exit); 어 테이터 헤더 행. –

+0

내 답변 편집, 사용 –

5

:

Live Demo

$('#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"> 
+0

@ 페카 : 감사합니다. 나는 브라우저가 그 기능을 다룰 것이라고 생각했다. :) – drudge

+1

당신은 아마도 '+'와 ''를 대체해야합니다. 그래서 당신은 끔찍한 '% 20'이 없습니다. – Bonzo

관련 문제