【问题标题】:Rewrite a query Parameter in a Sub Directory in .htaccess在 .htaccess 的子目录中重写查询参数
【发布时间】:2016-08-16 19:37:32
【问题描述】:

请帮助我使用 htaccess 从带有参数的子目录重写到另一个目录。编辑:我应该注意参数将来自用户输入,所以我需要关键字所在的通配符。

http://www.example.com/search/node?find=keyword

http://www.example.com/search/node/keyword

【问题讨论】:

    标签: .htaccess mod-rewrite


    【解决方案1】:

    您可以在 /root.htaccess 中使用以下规则:

    RewriteEngine on
    #1)Redirect "/search/node/?find=foo" to "/search/node/foo"#
    RewriteCond %{THE_REQUEST} /search/node/?\?find=([^\s]+) [NC]
    RewriteRule ^ /search/node/%1? [NC,L,R]
    #2)internally redirect "/search/node/foo" to "/search/node/?find=foo"#
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^search/node/(.+)$ /search/node/?find=$1 [QSA,NC,L]
    

    这将在内部将 /search/node/foo 重定向到 /search/node/?find=foo

    【讨论】:

    • 请看我的例子,我正在寻找相反的东西。从参数到干净的版本
    • 谢谢,你太棒了! 6 个多小时以来一直试图解决这个问题。
    猜你喜欢
    • 2023-02-14
    • 1970-01-01
    • 2019-05-28
    • 1970-01-01
    • 1970-01-01
    • 2014-01-27
    • 2012-05-06
    • 1970-01-01
    • 2021-04-11
    相关资源
    最近更新 更多