【问题标题】:.htaccess redirect parameter to sub-directory.htaccess 重定向参数到子目录
【发布时间】:2016-01-24 12:43:07
【问题描述】:

我正在尝试重定向页面,例如

www.domain.com/cat/listen?i=Name

www.domain.com/main/cat/subcat/name

我以前尝试过这些,但没有帮助。

Options +FollowSymlinks
RewriteEngine On
RewriteCond %{QUERY_STRING} i=(.*)
RewriteRule ^/cat/listen(.*) /main/cat/subcat/%1

RewriteEngine On
RewriteRule ^/?main/cat/subcat/([^/d]+)/?$ cat/listen?i=$1 [L,QSA]

我怀疑旧站点参数中的大写字母,但新站点使用 wordpress,所以我猜它不应该是问题的根源。

我也搜索并尝试了不同的方法,但无法弄清楚。我想我错过了一些非常简单的东西。

【问题讨论】:

    标签: apache .htaccess mod-rewrite redirect url-rewriting


    【解决方案1】:

    您的问题可能是 RewriteRule 模式中的 前导斜杠。在 htaccess 上下文中的 RewriteRule 中不需要前导斜杠。

    Options +FollowSymlinks
    RewriteEngine On
    RewriteCond %{QUERY_STRING} i=(.*) [NC]
    RewriteRule ^cat/listen(.*) /main/cat/subcat/%1? [R,L]
    

    目标网址末尾的空问号很重要,因为它会丢弃原始查询字符串。

    【讨论】:

      猜你喜欢
      • 2019-02-19
      • 1970-01-01
      • 1970-01-01
      • 2013-09-11
      • 2015-10-08
      • 1970-01-01
      • 2014-03-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多