1

重複の可能性:
方法: PHP での URL の書き換え?

index.php(mvc)の検索フォームからクリーンな URL を渡したい

すなわち:

 <form>
    <input type="text" name="search" onClick="if(this.value=='Search') this.value=''"    onBlur="if(this.value=='') this.value='Search'" value="Search"/>
    <button>Search</button>
</form> 

index.phpに送信され、検索パラメーターに応じて、つまり$_GET['search']検索コントローラーに渡されます。

しかし、代わりにindex.php?search=xyz合格したい/search/xyz

4

2 に答える 2

2

apache read about mod_rewrite/search/xyzを使用している場合は、index.php?search=xyz次のように書き換える書き換えルールを追加する必要があります。

RewriteEngine on 
Options +FollowSymlinks
RewriteBase / 

RewriteRule ^search/(.*) index.php?search=$1 [R]
于 2012-11-01T07:05:58.720 に答える
1

フォームのonsubmit関数でそれを行うことができます

<form onsubmit="myFunc();">  
..  

jsで:

function myFunc(){  
  var search_input = document.getElementById("search_input_id");
  window.location = "http://www.yoursite.com/search/"+search_input.value;}

これが機能するかどうかはわかりませんが、これでわかります。

UPD:あなたの場合:<button onclick="muFunc();">

そして、「'http://www.yoursite.com/search/search_term' を index.php?search=search_term にリダイレクトする方法」を意味する場合、Ruben Nagoga は 100% 正しいです

于 2012-11-01T07:04:58.657 に答える