3

I've got a problem with an old site (running EE2.4) which is issuing a 404 if the URL contains a querystring. This is happening on the homepage only.

i.e.

http://www.example.com/?foo=bar causes a 404

http://www.example.com?foo=bar causes a 404

http://www.example.com/abc/?foo=bar is fine

http://www.example.com/abc?foo=bar is fine

Index.php is being removed from the URLs using the following htaccess

RewriteCond $1 !\.(gif|jpe?g|png)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/$1 [L]

I have also tried adding the QSA paramater to the rewrite with no luck.

If I visit http://www.example.com/index.php then the homepage loads but as soon as I append a querystring it's back to the 404 page.

I have also tried setting the URI protocol to force querystrings but it still doesn't work (and adds ? characters within the URL of other pages).

It might also be pertinent to mention that this site is using Structure. I have tried turning off the "append trailing slash" feature therein.

Strict URLs is also turned on. But turning it off doesn't help.

The only way I can get this to work is to set the 404 page to be the homepage template. Then it works but obviously means that nonsense URLs will resolve to the homepage - which is undesirable.

1
  • Is there more to that .htaccess file we can look at? Rewrite rule order can be a nightmare.
    – jrothafer
    Commented Jul 16, 2015 at 16:20

2 Answers 2

3

I don't think the issue is with the friendly URL's, however you can test this by removing that block from the htaccess and typing the index.php part into your URL :

http://www.example.com/index.php?foo=bar

Another thing to check is that ExpressionEngine itself is not clearing the get parameters, which can happen as all ee actions are submitted to the home URL. To do this open up your /system/expressionengine/config/config.php file, and goto line 47 (in EE 2.10.1). CHange the $config['uri_protocol'] to "PATH_INFO". Give these 2 methods a go and see how you get on.

Please let us know if it helps or not!

Ref : https://ellislab.com/forums/viewthread/201950/

4
  • Using /index.php loads the homepage but as soon as I add a querystring it goes to the 404. I have also tried setting the uri_protocol config via the CP with no luck. I'll add an update to my question with some more info.
    – foamcow
    Commented Jul 16, 2015 at 16:06
  • darn, I was hoping the uri_protocol trick would do it. did you try setting uri_protocol to "QUERY_STRING" and retrying too? I've used that value before when EE would screw the pooch at query strings...
    – Blatant
    Commented Jul 16, 2015 at 16:19
  • 1
    I just checked the config file and it had been set to Query_String. Despite my changing it in the CP. I set it back to AUTO and things now seem to work. Problem is that I don't know why it would have been changed!
    – foamcow
    Commented Jul 16, 2015 at 16:26
  • The plot certainly thickens!! For point of reference a default install has the value set to "AUTO", for these things I always edit the file so I don't know about editing via CP and caches and such... Check Structure for anything that might require this change, thatss your prime candidate for changing a config like this.
    – Blatant
    Commented Jul 16, 2015 at 16:43
1

I had a situation where my web host required the use of a '?' after index.php in the .htaccess RewriteRule like this:

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

And changing the values of $config['uri_protocol'] in my /system/expressionengine/config/config.php file didn't solve the problem.

I finally solved it by creating a specific .htaccess rule that handled homepage requests with query strings, but ignored everything else.

Here's the original code from EllisLab on removing index.php from URLs with my added code in the second block of RewriteRules.

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /

  # Removes index.php from ExpressionEngine URLs
  RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
  RewriteCond %{REQUEST_URI} !/system/.* [NC]
  RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,NE,L]

  # Prevents query string on homepage URL from redirecting to 404 page in EE
  RewriteCond %{REQUEST_URI} ^/$ [NC]
  RewriteCond %{QUERY_STRING} (.+) [NC]
  RewriteRule .* index.php? [L]

  # Directs all EE web requests through the site index file
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^(.*)$ /index.php?/$1 [L]  
</IfModule>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.