Welcome Guest, Not a member yet? Register   Sign In
Root URL dies 404 if query string (?) is present
#1

[eluser]the_nix[/eluser]
My sub pages work fine:

Code:
http://www.example.com/controller/method?var=the_GET_vars_are_ignored_as_expected

However the home page dies 404 if a query string is present

Code:
http://www.example.com/?var=this_causes_404_error

I do not need the information that is contained in those query tags so any solutions that just strips them off is fine. I can't just change the inbound links because they are legacy URLs from external sites.

Copy of my .htaccess file:
Code:
<IfModule mod_rewrite.c>
    RewriteEngine On
    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>

Thanks!
#2

[eluser]slowgary[/eluser]
CI doesn't like query strings. It destroys the $_GET array by default, and throws an error when it gets query strings. Whether or not you're using the query strings, you should avoid having any links pointing to your site with query strings otherwise this will happen.

There's a config item in application/config.php that will enable query strings to avoid this problem.
#3

[eluser]Thorpe Obazee[/eluser]
Try playing the uri protocols in the config. I think PATH_INFO should work.
#4

[eluser]Colin Williams[/eluser]
This line "RewriteRule ^(.*)$ /index.php?/$1 [L]" is odd, but I see it a lot. Why "?/" and not just "/"?
#5

[eluser]the_nix[/eluser]
I replaced this line:

Code:
RewriteRule ^(.*)$ /index.php?/$1 [L]

with:

Code:
RewriteRule ^(.*)$ /index.php/$1 [L]

but now both the root domain as well as but sub pages with an explicit ? in the string die 404. It appears the trailing ? in the .htaccess allows CI to ignore the extra query string GET variables (that's what I want) but it's just not working on the root page e.g.,

Code:
http://www.example.com/?var=causing404error

Any other ideas?
#6

[eluser]the_nix[/eluser]
PS - I tried setting the URI_PROTOCOL to each of the four options. One succeeded in ignoring trailing ?var=causingproblems but then only my home page would load (it was ignoring my path). The other three did not help.
#7

[eluser]TheFuzzy0ne[/eluser]
Try changing lines similar to this:
Code:
RewriteRule ^(.*)$ /index.php?/$1 [L]

to this:
Code:
RewriteRule ^(.*)$ /index.php?/$1 [QSA,L]
#8

[eluser]Matthew Pennell[/eluser]
[quote author="TheFuzzy0ne" date="1244312495"]Try changing lines similar to this:
Code:
RewriteRule ^(.*)$ /index.php?/$1 [L]

to this:
Code:
RewriteRule ^(.*)$ /index.php?/$1 [QSA,L]
[/quote]
Has anyone solved this issue yet? The above suggestion didn't help me - I have a similar issue trying to track paid search that appends a querystring parameter to my homepage. The page just dies.

There must be a way to fix it, because the EE site works fine with querystrings.
#9

[eluser]Matthew Pennell[/eluser]
Actually, this page by LG looks like a potential solution, albeit a little hacky.
#10

[eluser]darri[/eluser]
I was looking for a way to make CI ignore a query string that paypal was sending it, and using this worked for me:
RewriteRule ^(.*)$ /index.php?/$1 [L]

Thanks!




Theme © iAndrew 2016 - Forum software by © MyBB