tags:

views:

631

answers:

2

Hi,

I have a codigniter site which does not like added url parameters for example mysite.com/page/value is good but mysite.com/page/value?url=parameters is bad.

Google ads campaigns attach url parameter for tracking, I want to get rid of these for the call to Codeigniter. (I know there are several ways to do it in codeigniter but I want to do it in htaccess level)

My htaccess is :

<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>

How should I change it to make it ignore url parameters but still accept mysite/a/b/ urls?

A: 

You could test if the query is not empty and stop the rewrite process:

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

Just put this rule before your others and any request with a query does not get beyond this rule.

Gumbo
I need codeigniter to receive the very same call as if the extra url parameters were not there. Stopping the rewrite if there are query parameters does not seem to achieve that.
Nir
+1  A: 

This should remove any query string:

RewriteCond %{QUERY_STRING} .
RewriteRule (.*) $1?
Jeremy Stein
Based on your solution I reached this RewriteCond %{QUERY_STRING} !^$ RewriteRule ^[/]?$ index.php?// [L] # if its the homepage # for any other page remove whats beyond the ? RewriteRule ^(.*)[?]?(.*)$ $1
Nir