0

我正在用 php 创建一个网站并使用 htaccess 重写规则。我隐藏核心 php 页面的 htaceess 代码是


RewriteCond %{REQUEST_URI} search
RewriteRule search /directory/search.php?&q=$1

我正在使用方法 GET in from 提交查询,表单是


<form action="http://<?php echo $_SERVER['SERVER_NAME']?>/search" method="GET">
<span><input type="text" name="q" class="search rounded" placeholder="Search something... :)" x-webkit-speech speech onwebkitspeechchange="this.form.submit();"></span>
</form>

我的 search.php 临时代码是


<?php

if(!isset( $_GET['q']))
    {
        echo '<p>Page is not set!</p>';
    }
        else
        {
            echo '<p>Search Page is running cool';
        }
?>

当我像搜索单词“hello”一样搜索表单时,它会显示 url “localhost/search?q=hello”

另一件事是我收到“内部服务器错误 500”

我正在使用 xampp,我认为我的 htaccess 首先无法正常工作,然后搜索表单没有发送正确的查询等等。所以请帮助我。

4

1 回答 1

0

你正在做的是一个 GET 请求类型。

需要将参数传递给初始重写变量。

尝试这个:

RewriteRule ^search/([^/]*)/$ /directory/search.php?&q=$1 [L]

要 POST 数据,而不是 GET:

RewriteRule ^search /directory/search.php?q=$1 [NC,P]

“P”的作用类似于“L”,它停止处理规则,但它也告诉模块该请求应该原封不动地传递给代理模块(意味着保留 POST 数据)。

此外,请确保打开重写引擎并设置选项。如果不打开重写引擎,它会给你一个 500 错误。

这是我通常使用的:

Options +FollowSymlinks
Options -MultiViews 
RewriteEngine On
RewriteBase /
ErrorDocument 404 /error.php
ErrorDocument 300 /error.php
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
于 2013-07-26T05:50:07.700 回答