如何删除htaccess中的url参数

时间:2009-12-10 12:55:01

标签: .htaccess

我有一个不喜欢添加网址参数的codigniter网站 比如mysite.com/page/value很好但是 mysite.com/page/value?url=parameters很糟糕。

Google广告系列附加了用于跟踪的url参数,我想摆脱对Codeigniter的调用。 (我知道在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> 

如何更改它以使其忽略url参数但仍接受mysite / a / b / urls?

2 个答案:

答案 0 :(得分:3)

这应该删除任何查询字符串:

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

答案 1 :(得分:1)

您可以测试查询是否为空并停止重写过程:

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

只需将此规则放在您的其他人之前,任何带有查询的请求都不会超出此规则。