al-dr
al-dr

Reputation: 147

htaccess redirection loose post data!! how to keep post data while redirect using htaccess?

I have a .htaccess file that rewrite .php to .htm:

Options +FollowSymLinks
RewriteEngine On
RewriteCond %{THE_REQUEST} ^[A-Z]+\s([^\s]+)\.php\s
RewriteRule .* %1.htm [L,R=301]
RewriteRule ^(.*)\.htm$ $1.php

The redirect works fine, But the redirection looses the $_POST data. How to keep $_POST data while redirecting?

Upvotes: 0

Views: 1062

Answers (2)

Lix
Lix

Reputation: 47976

If you want to simply rewrite the URL from .php files to .htm files, all you'll need to do is something like this -

RewriteEngine On
RewriteCond %{THE_REQUEST} ^[A-Z]+\s([^\s]+)\.php\s
RewriteRule ^(.*)\.php$ $1.htm

The 3 lines of the .htaccess detail the flowing behavior -

  1. Turn on the rewrite engine
  2. The request matches the given regular expression.
  3. Rewrite the entire URL to use a .htm file.

Upvotes: 0

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 798686

Browsers convert a POST request into a GET request on redirect. The RFC states that they should instead prompt the user if the method needs to change, but none of them follow that and instead force the method change unconditionally.

Upvotes: 1

Related Questions