2009-12-10 185 views
1

我有一個codigniter網站,不喜歡添加url參數 例如mysite.com/page/value是好的,但 mysite.com/page/value?url=parameters是壞的。如何刪除htaccess中的url參數

Google廣告系列附加url參數進行跟蹤,我想擺脫這些對Codeigniter的調用。 (我知道有幾個方法可以做到這一點的笨,但我想這樣做htaccess的水平)

我的htaccess是:

<IfModule mod_rewrite.c> 
    RewriteEngine On 

    # This is different between local host and production server!!! 
    RewriteBase/


    #Removes access to the system folder by users. 
    #Additionally this will allow you to create a System.php controller, 
    #previously this would not have been possible. 
    #'system' can be replaced if you have renamed your system folder. 
    RewriteCond %{REQUEST_URI} ^system.* 
    RewriteRule ^(.*)$ /index.php?/$1 [L] 

    #Checks to see if the user is attempting to access a valid file, 
    #such as an image or css document, if this isn't true it sends the 
    #request to index.php 
    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteRule ^(.*)$ index.php?/$1 [L] 
</IfModule> 

<IfModule !mod_rewrite.c> 
    # If we don't have mod_rewrite installed, all 404's 
    # can be sent to index.php, and everything works as normal. 
    # Submitted by: ElliotHaughin 

    ErrorDocument 404 /index.php 
</IfModule> 

我應該如何改變它,使之忽略的網址參數,但仍接受mysite/a/b/url?

回答

3

這應該刪除任何查詢字符串:

RewriteCond %{QUERY_STRING} . 
RewriteRule (.*) $1? 
+0

根據您的解決方案,我達到了這個 \t的RewriteCond%{QUERY_STRING}!^ $ \t重寫規則^ [/] $的index.php?// [L]#如果主頁 \t#任何其他頁remove什麼超越? \t RewriteRule ^(。*)[?]?(。*)$ $ 1 – Nir 2009-12-10 19:04:45

1

您可以測試如果查詢不爲空,並停止重寫的過程:

RewriteCond %{QUERY_STRING} !^$ 
RewriteRule^- [L] 

只要把你在別人面前這個規則,並查詢任何請求不超越這個規則。

+1

我需要笨接收非常同一呼叫如果額外的URL參數都沒有了。如果有查詢參數停止重寫似乎沒有達到那個目的。 – Nir 2009-12-10 13:05:23