Forum Moderators: phranque

Message Too Old, No Replies

Problems with htaccess losing POST data

         

davidhopkins

10:06 pm on May 29, 2012 (gmt 0)

10+ Year Member



Good afternoon all,

I have a site that has been developed using CodeIgniter, and i recently introduced a htaccess file in order to remove 'index.php' from all the links using a htaccess file provided by codeigniter. The file is


<IfModule mod_rewrite.c>
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>

<IfModule !mod_rewrite.c>
ErrorDocument 404 /index.php
</IfModule>


Now when i use this, all my POST data gets lost somehow and my scripts cant seem to find it, but as soon as i remove the htaccess file, the POST data works again.

Going through my code with a few members on the codeigniter forums shows that there are no errors with my codeing and must be a problem with the server setup somehow.

So i then got Live HTTP Headers extension for firefox and it displayed some results that i am puzzled by.

WHilst not using the htaccess file i get this response

http://example.com/index.php/login/ProcessLogin

POST /index.php/login/ProcessLogin HTTP/1.1
Host: example.com
User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:12.0) Gecko/20100101 Firefox/12.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-gb,en;q=0.5
Accept-Encoding: gzip, deflate
Connection: keep-alive
Referer: http://example.com/
Cookie: ci_session=a%3A5%3A%7Bs%3A10%3A%22session_id%22%3Bs%3A32%3A%227c2c22c673b1cb07a5644be3974ef21b%22%3Bs%3A10%3A%22ip_address%22%3Bs%3A11%3A%222.24.115.72%22%3Bs%3A10%3A%22user_agent%22%3Bs%3A65%3A%22Mozilla%2F5.0+%28Windows+NT+6.1%3B+rv%3A12.0%29+Gecko%2F20100101+Firefox%2F12.0%22%3Bs%3A13%3A%22last_activity%22%3Bi%3A1338322877%3Bs%3A9%3A%22user_data%22%3Bs%3A0%3A%22%22%3B%7D74b2f94a9d13cece028d47f7a066b3c6
Content-Type: application/x-www-form-urlencoded
Content-Length: 39
cid=g&email=gg&pass=&checkSubmit=Log+In
HTTP/1.1 200 OK
Date: Tue, 29 May 2012 20:23:39 GMT
Server: Apache/2.2.20 (Ubuntu)
X-Powered-By: PHP/5.3.6-13ubuntu3.7
Vary: Accept-Encoding
Content-Type: text/html
Transfer-Encoding: chunked
X-OSSProxy: OSSProxy 1.3.333.307 (Build 333.307 Win32 en-us)(Feb 22 2012 18:20:37)
Connection: keep-alive
----------------------------------------------------------


But when using the htaccess file which removes the index.php i get this response


http://example.com/login/ProcessLogin

POST /login/ProcessLogin HTTP/1.1
Host: example.com
User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:12.0) Gecko/20100101 Firefox/12.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-gb,en;q=0.5
Accept-Encoding: gzip, deflate
Connection: keep-alive
Referer: http://example.com/
Cookie: ci_session=a%3A5%3A%7Bs%3A10%3A%22session_id%22%3Bs%3A32%3A%227c2c22c673b1cb07a5644be3974ef21b%22%3Bs%3A10%3A%22ip_address%22%3Bs%3A11%3A%222.24.115.72%22%3Bs%3A10%3A%22user_agent%22%3Bs%3A65%3A%22Mozilla%2F5.0+%28Windows+NT+6.1%3B+rv%3A12.0%29+Gecko%2F20100101+Firefox%2F12.0%22%3Bs%3A13%3A%22last_activity%22%3Bi%3A1338322877%3Bs%3A9%3A%22user_data%22%3Bs%3A0%3A%22%22%3B%7D74b2f94a9d13cece028d47f7a066b3c6
Content-Type: application/x-www-form-urlencoded
Content-Length: 39
cid=g&email=gg&pass=&checkSubmit=Log+In
HTTP/1.1 404 Not Found
Date: Tue, 29 May 2012 20:24:53 GMT
Server: Apache/2.2.20 (Ubuntu)
X-Powered-By: PHP/5.3.6-13ubuntu3.7
Vary: Accept-Encoding
Content-Type: text/html
Transfer-Encoding: chunked
X-OSSProxy: OSSProxy 1.3.333.307 (Build 333.307 Win32 en-us)(Feb 22 2012 18:20:37)
Connection: keep-alive
----------------------------------------------------------


I get a HTTP/1.1 404 Not Found in there which i assme is the result of the loss of POST data?

Can anyone suggest any options for resolving this ?

Thanks

David

[edited by: incrediBILL at 11:12 am (utc) on May 30, 2012]
[edit reason] fixed URLS, use Example.com [/edit]

g1smd

10:36 pm on May 29, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



The htaccess file does not "remove the index.php".

That is not at all how it works.

mod_rewrite maps URL requests from "out there" on the web to an internal filepath "here" inside the server.

You're using an AcceptPathInfo method. Is that setting activated? It's extemely troublesome and not at all the way I would tackle implementing extensionless URLs.

The -f and -d tests are extremely inefficient. If that's standard code that ships with CodeIgnitor I'll be looking to have some words with someone there about that.

You should as a first step lose all four of the <ifModule> tags. They are not required here.