views:

247

answers:

1

First off I am using the Codeigniter Framework so this issue is a workaround the way CI process URLs along with the current redirects I have set up using mod_rewrite.

I am trying to get a URL like this /?gclid=somestringgoeshere to redirect to /index.php?/home/gclid/somestringgoeshere.

The current .htaccess I have set is below

<IfModule mod_rewrite.c>
    Options +FollowSymlinks
    RewriteEngine On
    RewriteCond %{REQUEST_URI} ^system.*
    RewriteRule ^(.*)$ /index.php?/$1 [L]


    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d

    RewriteRule ^([^_]+)-([^_]+)-([^_]+)-([^_]+)-([^_]+)-([^_]+)-([^.]+)$ index.php?/$1_$2_$3_$4_$5_$6_$7 [L]
    RewriteRule ^([^_]+)-([^_]+)-([^_]+)-([^_]+)-([^_]+)-([^.]+)$ index.php?/$1_$2_$3_$4_$5_$6 [L]
    RewriteRule ^([^_]+)-([^_]+)-([^_]+)-([^_]+)-([^.]+)$ index.php?/$1_$2_$3_$4_$5 [L]
    RewriteRule ^([^_]+)-([^_]+)-([^_]+)-([^.]+)$ index.php?/$1_$2_$3_$4 [L]
    RewriteRule ^([^_]+)-([^_]+)-([^.]+)$ index.php?/$1_$2_$3 [L]
    RewriteRule ^([^_]+)-([^.]+)$ index.php?/$1_$2 [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

    # This last condition enables access to the images and css folders, and the robots.txt file
    # Submitted by Michael Radlmaier (mradlmaier)

    RewriteCond $1 !^(index\.php|images|robots\.txt|css)
    RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>

I am trying to use the following code right above the first set up rewrite conditions and rule's to catch it before it try's anything else

RewriteRule ^?gclid=(.*)$ index.php?/home/gclid/$1 [L]

and

RewriteRule ^\?gclid=(.*)$ index.php?/home/gclid/$1 [L]

and

RewriteRule ^/?gclid=(.*)$ index.php?/home/gclid/$1 [L]

All either don't show the correct page or come up with a 500 internal error.

+1  A: 

The URI’s query can only be tested with the RewriteCond directive:

RewriteCond %{QUERY_STRING} ^gclid=(.*)
RewriteRule ^$ index.php?/home/gclid/%1 [L]

Or more general (will consider further query parameters):

RewriteCond %{QUERY_STRING} ^([^&]*&)*gclid=([^&]*)
RewriteRule ^$ index.php?/home/gclid/%2 [L]

Oh, by the way: RewriteCond directives only correspond to the first following RewriteRule directive.

Gumbo
It needs the ? in the url like this ^?gclid=(.*) but that shows an error too
Will Ayers
You can only test the URI path with the `RewriteRule` directive. The URI query (the part from the first `?` up to the first `#` after that) can only be accessed with the `%{QUERY_STRING}` variable. And that’s only possible with the `RewriteCond` directive. So my example should work.
Gumbo
found out there was some issue with the text that I copyied from your example, it inserted a weird character. Thanks!
Will Ayers