2010-01-10 103 views
1

我試圖讓搜索查詢搜索引擎優化。我有一個形式是這樣的:

<form action="index.php?<?=$_GET['search-input01']?>'" method="get"> 
    <p class="nom t-center"> 
    <label for="search-input01">All:</label> 
    <input type="text" size="75" name="q" id="search-input01" /> 
    <input type="image" src="design/search-button.gif" class="search-submit" /> 
    </p> 
</form> 

當u在地址欄中搜索做/index.php?q=SEARCHTERMHERE&x=0&y=0。我想這樣做:/search-SEARCHTERMHERE

怎麼辦?

回答

3

嘗試這樣:

if (isset($_GET['q'])) { 
    header('Location: http://example.com/search-'.rawurlencode($_GET['q'])); 
    exit; 
} 

這將重定向的網址查詢請求包含在你的/index.php?q=SEARCHTERMHERE&x=0&y=0/search-SEARCHTERMHERE一個q參數等。


編輯您也可以只用mod_rewrite的嘗試:

RewriteCond %{THE_REQUEST} ^GET\ /index\.php\? 
RewriteCond %{QUERY_STRING} ^(([^&]*&+)*)q=([^&]*)&*(.*) 
RewriteRule ^index\.php$ /search-%3?%1%4 [L,R] 

RewriteRule ^search-(.+) index.php?q=$1 [L,QSA] 

第一條規則是在外部重定向請求,第二個是爲內部重寫。

+1

感謝您的回答。你的代碼成功重定向但不工作。 mozilla說錯誤的重定向(從來沒有加載頁上ie)btw我改變了我的文章。忘記「www」這是搜索詞。我想/index.php?q=SEARCHTERMHERE&x=0&y=0到/ search-SEARCHTERMHERE – 2010-01-10 13:05:08

+0

它沒有工作,但我在php腳本$ _get中將「q」更改爲「search-input01」。它的工作原理如同search-TERM?x = 0&y = 0。並且頁面現在不工作。 RewriteRule search - (。*) - (。*)$ /index.php?type=$2&q=$1 - (。*) - (。*)$ /index.php?page=$2&q=$1 RewriteRule搜索 - (。*) - (。*) - (。*)$ /index.php?page=$3&type=$2&q=$1還有其他規則。如果你有MSN加我[email protected] – 2010-01-10 14:26:35

2

如果你想要做什麼濃湯建議相反,即重定向到/search-SEARCHTERM/index.php?q=SEARCHTERM&x=0&y=0,在你的.htaccess文件輸入這樣的事情:

RewriteEngine On 
RewriteRule ^search-([-_A-Za-z0-9]+)$ /index.php?q=$1&x=0&y=0 [L] 
+0

感謝您的更新。我試過 RewriteRule^search - ([-_A-Za-z0-9] +)$ /index.php?q=$1&x=0&y=0 [L] 但這不起作用 – 2010-01-10 13:05:49

+0

可以舉個例子一個典型的搜索字詞? – Tomba 2010-01-10 13:17:19

+0

um。前搜索詞:「窗口」,當你做搜索「窗口」在「所有」部分的頁面去「index.php?q = windows」在「應用程序」部分去「index.php?type = app&q = windows」 – 2010-01-10 13:21:12