【问题标题】:htaccess redirect dynamic get requesthtaccess 重定向动态获取请求
【发布时间】:2015-02-04 22:39:03
【问题描述】:

我需要重定向(不仅仅是重写)来自:

example.com/home/?s=keyword

到:

example.com/search/keyword

目前我正在尝试使用以下内容:

RewriteCond %{HTTP_HOST} ^example\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.example\.com$
RewriteRule ^/?$ "http\:\/\/www\.example\.com\/home\/" [R=301,L]

RewriteCond %{QUERY_STRING} ^/s=(.*)$
RewriteRule ^(.*?)$ search/$1 [NC,R,L]

我知道这是错误的,但我不知道如何解决它......

【问题讨论】:

    标签: .htaccess redirect get


    【解决方案1】:

    尝试:

    RewriteEngine On
    
    RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$
    RewriteRule ^/?$ http://www.example.com/home/ [R=301,L]
    
    RewriteCond %{THE_REQUEST} \ /+home/?\?s=([^&\ ]+)
    RewriteRule ^home/?$ /search/%1? [L,R]
    
    RewriteRule ^search/(.+)$ /home/?s=$1 [L]
    

    【讨论】:

    • 最后一行不相关,我不需要重写任何东西,只用get中的变量重定向。我怎样才能让它工作? (它现在给出 404)
    • @Sinros 去/search/keyword 给你404?因为那里什么都没有。
    • /search/keyword 无规则工作,它显示keyword 的结果我需要在/home/?s=abc 重定向请求,因此它将变为/search/abc
    • @Sinros 这就是第二条规则的作用
    猜你喜欢
    • 1970-01-01
    • 2019-03-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-03
    • 2019-01-18
    相关资源
    最近更新 更多