CodeIgniter Forums
.htaccess without the '?' : Working locally, but not on production server - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: .htaccess without the '?' : Working locally, but not on production server (/thread-31153.html)



.htaccess without the '?' : Working locally, but not on production server - El Forum - 06-08-2010

[eluser]BilliamTheSecond[/eluser]
I'm currently using this for .htaccess and config.php:
Code:
RewriteEngine on
DirectorySlash Off
RewriteCond $1 !^(assets|index\.php|robots\.txt)
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
Code:
$config['uri_protocol'] = "PATH_INFO";

It works perfectly on my local installation, but on production causes 404, with nothing going through the index script.

I can only get production working with
Code:
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
Code:
$config['uri_protocol'] = "REQUEST_URI";

But this setup means that any additional query string causes a 404 error. This kills some jquery scripts that add ?_=(timestamp) to ajax requests to avoid the cache.

My question is:
What could be causing the different behavior between the two installations? What can I change to make the first one above work on my production install?


.htaccess without the '?' : Working locally, but not on production server - El Forum - 06-08-2010

[eluser]Dan Horrigan[/eluser]
This is because most shared hosting servers (or cPanel servers) run PHP in CGI mode. When it runs in CGI mode, it forces you to use REQUEST_URI (because of an issue with the PHP core...PATH_INFO does not get rewritten correctly when in CGI mode). I believe in PHP 5.3 the issue has been fixed and you don't need the ?/ anymore, but cannot verify this.

Unfortunately you are stuck with running it this way unless you change hosts or something.

It shouldn't be that big of a deal though since you shouldn't be changing .htaccess or config.php too often.

Dan


.htaccess without the '?' : Working locally, but not on production server - El Forum - 06-08-2010

[eluser]Dan Horrigan[/eluser]
After a quick thought, you could try doing the following:

New .htaccess (we use it in PyroCMS):
http://pastie.org/996664

Then change the uri_protocol to AUTO.

That should work in both environments.

Dan


.htaccess without the '?' : Working locally, but not on production server - El Forum - 06-08-2010

[eluser]BilliamTheSecond[/eluser]
Thanks for the response. I was not aware of the path_info issue.

To clarify though, I don't mind having different setups for production and local development; I just need a working production setup Smile

Using request_uri and index.php?/$1 has this problem I mentioned:
Quote:.. this setup means that any additional query string causes a 404 error. This kills some jquery scripts that add ?_=(timestamp) to ajax requests to avoid the cache.

Ex: http://site.com works, but http://site.com? will 404
or
http://site.com/controller/method works but http://site.com/controller/method?anything-at-all will 404

I don't need query strings for my application, but I need those pages to work anyway.


.htaccess without the '?' : Working locally, but not on production server - El Forum - 06-08-2010

[eluser]Dan Horrigan[/eluser]
Unfortunately GET variables while using mod_rewrite has always been an issue in CI. I have a few hooks that I have written that will make it work for you. Give me a bit and I will post them up. I had them on my blog, but they need a few fixes and I think it is missing anyway.

Dan


.htaccess without the '?' : Working locally, but not on production server - El Forum - 06-08-2010

[eluser]Dan Horrigan[/eluser]
Here you go, give this a try:

http://github.com/dhorrigan/codeigniter-query-string

It should work with no issues. it basically fixes QUERY_STRING by removing the first "part" then goes the other important server vars and removes the actual Query String portions (but leaves the URI part). Then the 2nd hook rebuilds the $_GET array.

Let me know if it works for you. You should set your uri_protocol to AUTO.

Dan


.htaccess without the '?' : Working locally, but not on production server - El Forum - 06-08-2010

[eluser]BilliamTheSecond[/eluser]
It works, in that it fixes the 404 errors caused by query strings (awesome!).

[strike]Having to change to protocol to AUTO breaks things for me, where periods in segments are converted to underscores.[/strike]

[strike]Any chance your hooks could be made to work with uri_protocol = 'REQUEST_URI'?[/strike]

Nevermind! Works great Smile


.htaccess without the '?' : Working locally, but not on production server - El Forum - 06-08-2010

[eluser]Dan Horrigan[/eluser]
Did you try changing it to REQUEST_URI? If not, just try. If yes, what issues did it give you? Different environments act different so its hard to make it work for everyone.

Dan


.htaccess without the '?' : Working locally, but not on production server - El Forum - 06-08-2010

[eluser]BilliamTheSecond[/eluser]
It was a mix up on my end. Everything seems to be working exactly as I'd like. Thanks Dan!