kechx
V2EX  ›  Apache

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

  •  
  •   kechx · Sep 29, 2015 · 3626 views
    This topic created in 3904 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   ·   1199 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 37ms · UTC 23:44 · PVG 07:44 · LAX 16:44 · JFK 19:44
    ♥ Do have faith in what you're doing.