V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
kechx
V2EX  ›  Apache

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

  •  
  •   kechx · Sep 29, 2015 · 3587 views
    This topic created in 3877 days ago, the information mentioned may be changed or developed.

    原始:
    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 replies    2015-09-29 13:07:41 +08:00
    oott123
        1
    oott123  
       Sep 29, 2015 via Android
    RewriteEngine on
    RewriteRule ^sub-dir/index\.php$ /path-to-new-location/?%{QUERY_STRING} [L,R=301]
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3879 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 40ms · UTC 04:46 · PVG 12:46 · LAX 21:46 · JFK 00:46
    ♥ Do have faith in what you're doing.