【问题标题】:How to remove the variable of a form with GET without redirection [duplicate]如何在不重定向的情况下使用 GET 删除表单的变量 [重复]
【发布时间】:2012-09-18 05:29:24
【问题描述】:

可能重复:
Form Submit URL Formatting

我的表格很简单:

<form method="GET" action="http://{$smarty.server.SERVER_NAME}/recherche/">
        <input type="text" name="s" value="Recherche" class="text" id="searchbox" />
        <input type="submit" class="search" value="Rechercher !" title="Rechercher !" />
</form>

当我提交我的表单时,网址会带我进入:

http://mywebsite.com/recherche/?s=mysearch

但我像这样正确地重写了网址:

# Recherche
RewriteRule ^recherche/([^/]*)$ /index.php?page=recherche&s=$1 [L]

但我不知道如何获取正确的网址(没有 &s=)没有重定向

【问题讨论】:

    标签: html forms search url-rewriting get


    【解决方案1】:

    您的重写规则:RewriteRule ^recherche/([^/]*)$ /index.php?page=recherche&amp;s=$1 [L] 仅在服务器内部向一个方向重写。该规则对浏览器没有任何影响,除了响应类似/recherche/something 的请求而发送的内容。如果您确实希望更改地址栏中的 URL,则需要redirect 响应请求,而不是在内部进行一些 URI 修改并返回内容。为此,您需要:

    RewriteCond %{THE_REQUEST} ^GET\ /recherche/\?s=([^&\ ]+)
    RewriteRule ^recherche/$ /recherche/%1? [L,R=301]
    

    然后你就有了你的规则:

    RewriteRule ^recherche/([^/]*)$ /index.php?page=recherche&s=$1 [L]
    

    他们两个应该一起工作。一种将浏览器重定向到不带查询字符串的 URL,另一种采用不带查询字符串的 URL,并在内部将其重写为查询字符串。

    【讨论】:

    • 因此,我有义务进行重定向!但它比 php 中的条件更干净...谢谢 Jon Lin =)
    猜你喜欢
    • 2021-10-05
    • 1970-01-01
    • 2015-06-14
    • 2023-04-06
    • 2017-07-06
    • 2014-08-26
    • 2015-06-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多