【问题标题】:GET request htaccess redirectionGET 请求 htaccess 重定向
【发布时间】:2014-04-21 11:40:09
【问题描述】:

我需要从

重定向 url

website.com/search.php?city=india&keyword=laptop

website.com/search/india/laptop

我怎样才能用 htaccess 做到这一点

在我的 htaccess 中显示代码

Options +FollowSymLinks

RewriteEngine on

RewriteRule ^([a-z0-9_-]+)/([a-z0-9_-]+)(/)?$ search.php?city=$1&keyword=$2

【问题讨论】:

    标签: regex apache .htaccess mod-rewrite redirect


    【解决方案1】:

    您可以在根 .htaccess 文件中使用此规则:

    Options +FollowSymLinks -MultiViews
    
    RewriteEngine on
    
    RewriteCond %{THE_REQUEST} \s/+search\.php\?city=([^&]+)&keyword=([^\s&]+) [NC]
    RewriteRule ^ /search/%1/%2? [R=301,L,NE]
    
    RewriteRule ^search/([\w-]+)/([\w-]+)/?$ /search.php?city=$1&keyword=$2 [L,QSA]
    

    【讨论】:

    • justdlal.com/search.php?city=india&keyword=laptop 仍然保持不变,但不会重定向到 justdlal.com/search/india/laptop
    • 还有一个帮助... url 解析为 justdlal.com/search/india/lenovo+laptop+dealers 如何删除字符串中的 + 符号,以便 url 为 justdlal.com/search/india /联想笔记本电脑经销商
    • 这与这个问题非常不同。请用它创建一个新问题,我会尽力回答。
    猜你喜欢
    • 1970-01-01
    • 2013-11-02
    • 2015-04-08
    • 1970-01-01
    • 1970-01-01
    • 2016-04-03
    • 2019-12-16
    • 2012-03-13
    • 2012-08-16
    相关资源
    最近更新 更多