V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
RihcardLu
V2EX  ›  Apache

带参数的 URL 重定向规则如何写

  •  
  •   RihcardLu · 2015-09-29 10:20:57 +08:00 · 3008 次点击
    这是一个创建于 3125 天前的主题,其中的信息可能已经有所发展或是发生改变。

    原始:
    http://www.example.com/sub-dir/index.php?id=1

    定向后:
    http://www.example.com/path-to-new-location/

    网上查找到的可以这么写,但是实际测试无效

    RewriteEngine on
    RewriteCond %{QUERY_STRING} id=1
    RewriteRule ^sub-dir/index\.php$ /path-to-new-location/? [L,R=301]
    

    参考:Common .htaccess Redirects

    1 条回复    2015-09-29 13:07:41 +08:00
    oott123
        1
    oott123  
       2015-09-29 13:07:41 +08:00 via Android
    RewriteEngine on
    RewriteRule ^sub-dir/index\.php$ /path-to-new-location/?%{QUERY_STRING} [L,R=301]
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1463 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 17:17 · PVG 01:17 · LAX 10:17 · JFK 13:17
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.