2010-01-10 104 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