4 Replies - 2444 Views - Last Post: 26 November 2012 - 07:34 AM

#1 goku87  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 4
  • View blog
  • Posts: 81
  • Joined: 17-October 09

.htaccess preventing $_POST

Posted 25 November 2012 - 09:05 AM

In a nutshell, the .htaccess is preventing $_POST from passing variables between pages. The only thing, so far, that I've been able to dig up from the internet is that this issue frustrates others just as it does myself. Forms post fine without the .htaccess file, but do not with the file. This happens both on my server and localhost.

I'd be okay with a "hack" that prevented the rewrite of /?page=confirm as it's the only page that needs access to the post data, but I'm not sure how to go about excluding that in the rewrite conditions. I would prefer an actual fix as opposed to a hack, though.

Here is the .htaccess file I'm using:
RewriteEngine on
Options +FollowSymlinks
RewriteBase / 

RewriteCond %{REQUEST_URI} !\.(css|js|jpe?g|png|gif|ttf|eot|swf)$ [NC]
RewriteRule ^([^/]+)/? index.php?page=$1 [L,QSA]
RewriteCond %{QUERY_STRING} (.*?)page=(\w+)(.*)
RewriteRule ^ /%2?%1%3 [L,R=301]


This post has been edited by Atli: 25 November 2012 - 09:53 AM


Is This A Good Question/Topic? 0
  • +

Replies To: .htaccess preventing $_POST

#2 Atli  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3730
  • View blog
  • Posts: 6,017
  • Joined: 08-June 10

Re: .htaccess preventing $_POST

Posted 25 November 2012 - 10:12 AM

I'm not entirely sure why this would be happening. I've never had any trouble accessing POST data when using mod_rewrite like that. Could you dump the $_SERVER array and show that to us? I'm curious to see exactly what kind of request PHP is getting.

As a "hack", you could add a RewriteCond that specifically eliminates a page created for the sole purpose of processing the post data.
RewriteCond %{REQUEST_URI} !^confirm.php$ [NC]


Note exactly elegant, but since I'm not sure what's causing the problem it's the only thing I can suggest.
Was This Post Helpful? 0
  • +
  • -

#3 goku87  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 4
  • View blog
  • Posts: 81
  • Joined: 17-October 09

Re: .htaccess preventing $_POST

Posted 25 November 2012 - 10:56 AM

Here's both the $_SERVER and $_POST vars:

$_SERVER:Array
(
    [DOCUMENT_ROOT] => /home/feralcre/public_html
    [GATEWAY_INTERFACE] => CGI/1.1
    [HTTP_ACCEPT] => text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
    [HTTP_ACCEPT_ENCODING] => gzip, deflate
    [HTTP_ACCEPT_LANGUAGE] => en-us,en;q=0.5
    [HTTP_CONNECTION] => keep-alive
    [HTTP_COOKIE] => __utma=169570998.1319319389.1351652930.1353860421.1353864558.12; __utmz=169570998.1351652930.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); fc=fcVal=2512376726447736263; PHPSESSID=72557876007c686509c62ebcb3227e4a; __utmb=169570998.44.10.1353864558; __utmc=169570998
    [HTTP_HOST] => feralcreature.com
    [HTTP_REFERER] => http://feralcreature.com/admin?&action=settings
    [HTTP_USER_AGENT] => Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:15.0) Gecko/20120830 Firefox/15.0
    [PATH] => /bin:/usr/bin
    [QUERY_STRING] => page=index.php&page=confirm
    [REDIRECT_QUERY_STRING] => page=confirm
    [REDIRECT_STATUS] => 200
    [REDIRECT_URL] => /confirm
    [REMOTE_ADDR] => 65.191.27.4
    [REMOTE_PORT] => 62806
    [REQUEST_METHOD] => GET
    [REQUEST_URI] => /confirm
    [SCRIPT_FILENAME] => /home/feralcre/public_html/index.php
    [SCRIPT_NAME] => /index.php
    [SERVER_ADDR] => 72.167.247.193
    [SERVER_ADMIN] => webmaster@feralcreature.com
    [SERVER_NAME] => feralcreature.com
    [SERVER_PORT] => 80
    [SERVER_PROTOCOL] => HTTP/1.1
    [SERVER_SIGNATURE] => 
Apache/2.2.17 (Unix) mod_ssl/2.2.17 OpenSSL/0.9.8e-fips-rhel5 mod_auth_passthrough/2.1 mod_bwlimited/1.4 FrontPage/5.0.2.2635 Server at feralcreature.com Port 80


    [SERVER_SOFTWARE] => Apache/2.2.17 (Unix) mod_ssl/2.2.17 OpenSSL/0.9.8e-fips-rhel5 mod_auth_passthrough/2.1 mod_bwlimited/1.4 FrontPage/5.0.2.2635
    [PHP_SELF] => /index.php
    [REQUEST_TIME] => 1353866059
    [argv] => Array
        (
            [0] => page=index.php&page=confirm
        )

    [argc] => 1
)
$_POST:Array
(
)

Was This Post Helpful? 0
  • +
  • -

#4 goku87  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 4
  • View blog
  • Posts: 81
  • Joined: 17-October 09

Re: .htaccess preventing $_POST

Posted 25 November 2012 - 03:57 PM

Maybe I didn't do the "hack" right, but it's also not working. Here is how I put it in twice because I wasn't quite sure how it was to be done:

RewriteEngine on
Options +FollowSymlinks
RewriteBase / 

RewriteCond %{REQUEST_URI} !\.(css|js|jpe?g|png|gif|ttf|eot|swf)$ [NC]
RewriteCond %{REQUEST_URI} !^confirm.php$ [NC]
RewriteRule ^([^/]+)/? index.php?page=$1 [L,QSA]
RewriteCond %{REQUEST_URI} !^confirm.php$ [NC]
RewriteCond %{QUERY_STRING} (.*?)page=(\w+)(.*)
RewriteRule ^ /%2?%1%3 [L,R=301]

Was This Post Helpful? 0
  • +
  • -

#5 Atli  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3730
  • View blog
  • Posts: 6,017
  • Joined: 08-June 10

Re: .htaccess preventing $_POST

Posted 26 November 2012 - 07:34 AM

OK, I can see two potential problems now.

First, as the QUERY_STRING value there highlights, your first RewriteRule is being executed twice. After the URL is rewritten using mod_rewrite, the rewritten URL is executed, basically, as a new request, which means the entire mod_rewrite bit is executed again using the new URL. Which means that the first RewriteRule sends the URL through three stages:
1: /confirm (the original)
2: /index.php?page=confirm (After run #1)
3: /index.php?page=index.php&page=confirm


What happens there with the third stage is that the second value also matches the first RewriteRule, and is therefore processed again, generating two "page" values, since the original page value is still there. You need to be more specific about what values your first RewriteRule is going to accept, or add a RewriteCond clause that specifically excludes processing it on the "index.php" page.

Second, the second RewriteRule would execute on any URL that includes the "page=(\w+)", which includes the final output of the first RewriteRule. I'm guessing this is what's causing the final request to end up as a GET request, rather than the expected POST request.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1