kechx
V2EX  ›  Apache

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

  •  
  •   kechx · Sep 29, 2015 · 3704 views
    This topic created in 3948 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   ·   5567 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 74ms · UTC 09:00 · PVG 17:00 · LAX 02:00 · JFK 05:00
    ♥ Do have faith in what you're doing.