2012-01-18 10 views
0

経由でリダイレクト:PHP/htaccessの私が欲しいGET

  • sub.domain.com/custom/index.php

をロードするためにindex.php

  • sub.domain.com?s=customをロードするために、私は今、この権利をやっている:

    を.htaccessファイルで:

    RewriteRule ^(custom)/?$ index.php?subject=$1 
    

    index.phpに私はこれがあります。

    if($_GET['s'] == 'custom') { 
        header('Location: http://sub.domain.com/custom/index.php') ; 
    } 
    

    を...しかし、それはGET変数に応じて、htaccessファイル自体を経由してリダイレクトを行うことが可能ですか?

    ありがとうございます!

  • 答えて

    1

    で再生する必要があります既存の「カスタム」getパラメータを持つすべてのリクエストをindex.phpにリダイレクトします。これは拡張可能です:)

    アイデア:http://statichtml.com/2010/mod-rewrite-baseon-on-query-string.html

    +0

    'custom =(。*)'ではなく 's =(。*)'であるべきですか? – 3zzy

    +0

    はい、良い点 – Kristian

    +0

    ありがとうございます。また、現在、クエリ文字列を/ customにリダイレクトしていますが、個別にリダイレクトしたいのですが? – 3zzy

    0

    あなたはおそらく "に、RedirectMatch" を使用したい

    RedirectMatch ^sub.domain.com?s=custom$ /custom/index.php 
    

    多分youllのは、はい、あなたがするRewriteCond

    これにより
    RewriteCond %{QUERY_STRING} s=custom 
    RewriteRule ^(.*?)$ custom/index.php [L] 
    

    でクエリ文字列をチェックすることができ、正規表現のabit

    関連する問題