Yesh
Yesh

Reputation: 63

POST not working after mod_rewrite

Here is my htaccess

Options -Indexes
<IfModule dir_module>
DirectoryIndex in.php
</IfModule>
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteRule \.(css|jpe?g|gif|png|js|css|htm|html|mp3|wav|ico)$ - [L]
RewriteBase /
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]


RewriteCond %{THE_REQUEST} ^[A-Z]+\ /([^/]+/)*[^.#?\ ]+\.php([#?][^\ ]*)?\ HTTP/
RewriteRule ^(([^/]+/)*[^.]+)\.php http://www.example.com/$1 [R=301,L]

RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^some/(.*)/(.*)/$ test.php?z=$1&n=$2 [NC,L]
RewriteRule ^some/(.*)/(.*)$ test.php?z=$1&n=$2 [NC,L]
RewriteRule ^some/(.*)/$ test.php?z=$1 [NC,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !.*test.php$ [NC]
RewriteRule ^([^\.]+)$ $1.php [NC,L]

None of the $_POST with relative paths are working after implementing mod_rewrite.

Note :I have already set < base href="http://example.com/"/> and RewriteBase / as mentioned above

I have gone through other questions at SO but no luck!

Thanks for your advise!

I'm sorry.. Not working in the sense, POST variables are probably getting lost during htaccess redirects ???

Upvotes: 0

Views: 1182

Answers (1)

Aaron Saray
Aaron Saray

Reputation: 1177

I would validate the code you are using to build your form actions. I agree with the above commentors that you are losing your POST variables because of the redirect.

Why might this be happening?

First off, that rewrite rule to redirect from non-www to www should only happen the first time someone visits your website without the www's. You should program accordingly.

Ie - someone types in 'example.com' - your rewrite will take them to 'www.example.com'

From then on, if you must refer to your full domain in a form, use the entire WWW version.

<form action="http://www.example.com/processForm.php" method="POST">

Alternatively, you could stop using the full domain.

A common place I've seen this happen is when programmers use plugins that define a configuration object. Perhaps that configuration object is pointing to the non www version by accident. Imagine this code:

$config = array('domain'=>'example.com', 'othersettings'=>'more here');

Forms are sometimes created doing this:

<form action="<?php echo $config['domain'] ?>/processForm.php" method="POST">

See, that would get translated into the non-www version, losing your POST values.

Good luck!

Upvotes: 1

Related Questions