【问题标题】:htaccess dynamic URLs redirecthtaccess 动态 URL 重定向
【发布时间】:2016-09-18 06:41:00
【问题描述】:

您好,我想将一些动态 URL 重定向到一些静态 URL 例如

  • /folder/index.php?rid=321

  • http://example.com/folder/some-name-321.htm

  • /folder/index.php?rid=324

  • http://example.com/folder/some-other-name-324.htm

我试过了

Redirect 301 /folder/index.php?rid=321 http ://example.com/folder/some-name-321.htm
Redirect 301 /folder/index.php?rid=324 http ://example.com/folder/some-other-324.htm

但不工作。 我应该如何重定向这些 URL 另外,我应该在哪里放置我的 htaccess 文件。 这应该在 /folder/.htaccess 中,或者我应该将规则放在站点根目录中的主 htaccess 文件中。

亲切的问候

【问题讨论】:

    标签: apache .htaccess redirect mod-rewrite


    【解决方案1】:

    您永远无法使用 Redirect (mod-alias) 指令匹配查询字符串。要操作查询字符串,您需要使用mod-rewrite /root.htaccess 中的以下规则

    RewriteEngine on
    
    
    RewriteCond %{QUERY_STRING} ^rid=(.+)$
    RewriteRule ^index\.php$ http://example.com/folder/some-name-%1.htm? [NC,L,R]
    

    【讨论】:

    • 我试过这个,但没有用,在我访问 /folder/index.php?rid=321 尝试这个之后,它没有重定向到 http://example.com/folder/some- name-321.htm
    • 好吧,我使用了以下 RewriteCond %{QUERY_STRING} (^|&)rid=325($|&) RewriteRule ^folder/index\.php$ /folder/some-name-325。 htm [L,R=301] 但它重定向到example.com/folder/some-name-325.htm?rid=325 而我只需要example.com/folder/some-name-325.htm
    猜你喜欢
    • 2015-10-01
    • 2021-06-30
    • 2021-04-10
    • 1970-01-01
    • 1970-01-01
    • 2013-06-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多