Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 使用mod_rewrite和$\u GET_Php_.htaccess_Forms_Get - Fatal编程技术网

Php 使用mod_rewrite和$\u GET

Php 使用mod_rewrite和$\u GET,php,.htaccess,forms,get,Php,.htaccess,Forms,Get,我正在尝试做搜索引擎优化来搜索查询。我有一张这样的表格: <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" i

我正在尝试做搜索引擎优化来搜索查询。我有一张这样的表格:

 <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>
if (isset($_GET['q'])) {
    header('Location: http://example.com/search-'.rawurlencode($_GET['q']));
    exit;
}
当你在地址栏中搜索/index.php时,q=SEARCHTERMHERE&x=0&y=0。我想在这里搜索:/SearchTerm


怎么办

试试这样的方法:

 <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>
if (isset($_GET['q'])) {
    header('Location: http://example.com/search-'.rawurlencode($_GET['q']));
    exit;
}
这将把URL查询中包含q参数的请求重定向到/index.php?q=SEARCHTERMHERE&x=0&y=0到/SEARCHTERMHERE

编辑您也可以仅使用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]

第一条规则是从外部重定向请求,第二条规则是内部重写。

尝试以下操作:

 <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>
if (isset($_GET['q'])) {
    header('Location: http://example.com/search-'.rawurlencode($_GET['q']));
    exit;
}
这将把URL查询中包含q参数的请求重定向到/index.php?q=SEARCHTERMHERE&x=0&y=0到/SEARCHTERMHERE

编辑您也可以仅使用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]

第一条规则是从外部重定向请求,第二条规则是内部重写。

如果要执行与Gumbo建议相反的操作,即将/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]

如果要执行与Gumbo建议相反的操作,即将/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]

谢谢你的回答。代码重定向成功,但不起作用。mozilla说错误的重定向从未在ie上加载页面。顺便说一句,我更改了我的帖子。忘了www吧,那是搜索词。我想要/index.php?q=SEARCHTERMHERE&x=0&y=0到/searchsearchterm这里它不起作用,但我在php脚本$\u get中将q改为search-input01。它可以工作,但编写起来像搜索词?x=0&y=0。页面现在不工作了。重写规则搜索-.*-.*$/index.php?page=$2&q=$1重写规则搜索-.*-.*$/index.php?type=$2&q=$1重写规则搜索-.*-.*-.*$/index.php?page=$3&type=$2&q=$1还有其他规则。如果你有MSN添加我alee@depyronick.comthank谢谢你的回答。代码重定向成功,但不起作用。mozilla说错误的重定向从未在ie上加载页面。顺便说一句,我更改了我的帖子。忘了www吧,那是搜索词。我想要/index.php?q=SEARCHTERMHERE&x=0&y=0到/searchsearchterm这里它不起作用,但我在php脚本$\u get中将q改为search-input01。它可以工作,但编写起来像搜索词?x=0&y=0。页面现在不工作了。重写规则搜索-.*-.*$/index.php?page=$2&q=$1重写规则搜索-.*-.*$/index.php?type=$2&q=$1重写规则搜索-.*-.*-.*$/index.php?page=$3&type=$2&q=$1还有其他规则。如果你有MSN添加我alee@depyronick.comthanks更新。我尝试重写规则^search-[-\u A-Za-z0-9]+$/index.php?q=$1&x=0&y=0[L],但这不起作用。你能给出一个典型搜索词的示例吗?嗯。ex search term:windows当您在所有部分中搜索窗口时,页面转到index.php?q=windows in applications部分转到index.php?type=app&q=windows如果index.php不在服务器根目录中,请删除/before index.php。您是否尝试添加到index.php以查看传递了哪些参数?感谢更新。我尝试重写规则^search-[-\u A-Za-z0-9]+$/index.php?q=$1&x=0&y=0[L],但这不起作用。你能给出一个典型搜索词的示例吗?嗯。ex search term:windows当您在所有部分中搜索窗口时,页面转到index.php?q=windows in applications部分转到index.php?type=app&q=windows如果index.php不在服务器根目录中,请删除/before index.php。您是否尝试添加到index.php以查看传递了哪些参数?