2012-01-20 23 views
9

URLの書き換えに問題があります。.htaccess URL書き換えチャレンジ

以下のものはすべて正常に動作しますが、URLからクエリーストリングを削除するルールを追加する必要があります。

site.com/page?a=b

site.com/pageになるだろう誰かが助けることはできますか?私は.htaccessに関するいくつかの読書をしましたが、それは非常に複雑です。また、新しいディレクティブが表示されるファイルの場所を知る必要があります。

ありがとうございました。

 

    # EE 404 page for missing pages 
    ErrorDocument 404 /index.php/404/index 

    # Simple 404 for missing files 
    
     ErrorDocument 404 "File Not Found" 
    

    # Rewriting will likely already be on, uncomment if it isnt 
    
    RewriteEngine On 
    RewriteBase/
    

    # Block access to "hidden" directories whose names begin with a period. This 
    # includes directories used by version control systems such as Subversion or Git. 
    
     RewriteRule "(^|/)\." - [F] 
    

    # remove the www - Uncomment to activate 
    # 
    # RewriteCond %{HTTPS} !=on 
    # RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC] 
    # RewriteRule ^(.*)$ http://%1/$1 [R=301,L] 
    # 

    # Remove the trailing slash to paths without an extension 
    # Uncomment to activate 
    # 
    # RewriteRule ^(.*)/$ /$1 [R=301,L] 
    # 

    # Remove index.php 
    # Uses the "include method" 
    # http://expressionengine.com/wiki/Remove_index.php_From_URLs/#Include_List_Method 
    # 
    RewriteCond %{QUERY_STRING} !^(ACT=.*)$ [NC] 
    RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5})$ 
    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteCond %{REQUEST_URI} ^/(home|inc|publishers|sidebars|about|include-template|testing|advertisers|products|sitemap|style|ad-choices|social-bar|search|404||members|P[0-9]{2,8}) [NC] 
    RewriteRule (.*) /index.php/$1 [L] 

+0

最後のルールで '$ 1'の後に'? 'を追加するだけです。 'RewriteRule(。*)/index.php/$1? [L] ' – Virendra

答えて

9

これはURL

RewriteRule ^(.*) /index.php/$1? [L] #remove query string 

からクエリ文字列を削除しますが、それは私が答えのために少し遅れだけど、私は同様の動作を探していたことから、私は思っ

2

を役に立てば幸い私はそれを共有する必要があります:あなたはまた、クエリ文字列を削除する書き換えルールにフラグを追加することができます。フラグは[QSD]であり、末尾の?のような回避策を避けるのに役立ちます。

Hereこのフラグの詳細については、こちらをご覧ください。 "このフラグは[Apache]バージョン2.4.0以降で利用できます"