2012-01-20 51 views
9

我遇到了一些URL重寫問題。.htaccess URL重寫挑戰

下面的所有東西都正常工作,但我需要添加一個從URLS中刪除querystrings的規則。

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

這從網址

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

刪除查詢字符串希望它可以幫助

2

我有點晚了一個答案,但因爲我正在尋找一個類似的行爲,我想我應該分享它:你也可以添加一個標誌到重寫規則中去除查詢字符串;該標誌是[QSD],它有助於避免在最後?變通辦法;-)

Here您可以找到更多有關此標誌。我想指出:「此標誌在[Apache]版本2.4.0和更高版本中可用」