Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apache .htaccess redirect removes form data

To maintain consistency across my app, I need all requests to include www so I use .htaccess file like this:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} !^(www\.) [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,QSA,NC,L]
</IfModule>

It works just fine. HOWEVER, when POST requests are sent without the www the form data gets stripped out. Is this expected? Is there a way to correct this?

like image 534
emersonthis Avatar asked Dec 01 '25 04:12

emersonthis


1 Answers

A Redirect response with status such as 301,302, or 303 is always handled as a GET in every browser I've encountered. Hence, a POST request redirected will be seen by the client browser and it will issue a GET request to the URL provided in the redirect response. See my answer to the following question and the comments others added for details how you might work around this gracefully: Apache 301 Redirect and preserving post data

like image 141
Ray Avatar answered Dec 03 '25 19:12

Ray



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!