Seems like POST values are lost when .htaccess RewriteRule used. GET values are OK. How to fix?

Related searches

Several days ago I had a question about removing index.php from the address bar, so the address of the page looks shorter and better. The shortest solution of this problem was (RewriteRule ^index.php / [L,R=301] in the .htaccess file). And it works!

Since I put that string into the .htaccess, some pages are redirected to the main page. I spent a lot of time to guess, why. As I understand, the answer is: with RewriteRule ^index.php / [L,R=301], $_POST parameters are not sent to the next page. $_GET parameters are OK. Once I remove RewriteRule ^index.php / [L,R=301] from .htaccess, everything becomes fine as usual. Why does it happen and how to fix that?

Thank you.

The [R] flag will incur a redirect. And user-agents issue a redirect as GET request. There is nothing that can be done if you really want to shorten URLs down to the / root path.

You could however block POST requests specifically from being rewritten/redirected:

RewriteRule ^index.php / [L,R=301]

htaccess tricks and tips.. part two: url rewriting with mod rewrite, Seems like POST values are lost when .htaccess RewriteRule used. GET values are OK. How to fix? 发表于2019-9-24 | | 暂无分类. Several days ago I had a� Teams. Q&A for Work. Stack Overflow for Teams is a private, secure spot for you and your coworkers to find and share information.

You could try using [L,R=307] instead. 307's must not change the request-method according to the spec, but I don't know how browser implemented 307.

But the root of the problem is the use of <form action="____/index.php" ...

Just leave the action empty to POST to the current url e.g.

Htaccess Mod_Rewrite - Crazy Advanced Master Class, Seems like POST values are lost when .htaccess RewriteRule used. GET values are OK. How to fix? | Q&A ProDevsBlog. To avoid issues with some proxies and Apache rewrites, pass in POST data or set the Content-Length: 0 header for requests with an empty body.. I recently had issues with Apache converting my request to a GET when doing a POST with an empty body.

I'm using something like:

<IfModule mod_rewrite.c>

RewriteEngine on

RewriteCond %{REQUEST_URI} !^/(css|images|js)/

# don't rewrite existing files, directories and links

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l

# rewrite everything else to index.php

RewriteRule .* index.php [L]


And its working for all requests, rewriting it via index.php file. If you need to redirect 301 (which stands for Moved Permanently code) check out this question: Is it possible to redirect post data?

Htaccess, for that folder. if this directive is in you main .htaccess file, then the ReWrite of a ReWriteRule is just fine when using a simple $_GET variable, but sometimes you For example, to check if the above cookie exists and has the correct value set, well as $_POST , $_SESSION , and $_SERVER arrays, special variables, like � When I try to POST data from a html page using POST method I get a 302 redirect, and the webserver redirects to homepage of the website. But when I use GET method to send data, it redirects to the intended page. See the below HTML page I used and the URL I tried to redirect. POST 302 Redirect Test. Order Id : Order Id :

POST values will NEVER survive an external redirect (the R=301), it's a security liability, so browsers will never support that. Remove the R=301 and you will be fine. You just should alter all existing links to the page to the shorter/prettier one (<a>'s but also form actions etc.)

Get ready to explode your learning curve, I figured something out. So when I realized my problem was that I didn't know the value of the variable Its almost the same as being able to spoof POST requests! Ok, so I've prepared the . htaccess code you can use to view the values of all these variables. But try not to let absolute power corrupt you. Because you may find yourself misusing the .htaccess file. When all you have is a hammer, then every task can start to look like a nail. But at least sometimes, when something seems like an .htaccess task, your directive is better off somewhere else.

I had the same problems but my htacces was like this:

RewriteEngine on
RewriteRule .* index.php [NC]

Just change NC for L and everything works fine.

Final code:

RewriteEngine on
RewriteRule .* index.php [L]

This code sends the Set-Cookie header to create a cookie on the client with the value of a matching item in 2nd parantheses. RewriteRule ^(.*)(� You can use the find_elements_by_ like so: parentElement = driver.find_element_by_class("bar") elementList = parentElement.find_elements_by_tag_name("li") If you want help with a specific case, you can edit your post with the HTML you’re looking to get parent and children elements from.

If you need to know how to do basic and common URL rewriting, please take a look at our SEO Friendly URL Rewriting post. Use RewriteCond. We were used to use RewriteRule to match a URL, and then rewrite it. However, RewriteRule will always ignore your query string (GET data) so we need to use RewriteCond to capture the values in the query string.

Assuming the robots will respect the robots.txt, then it wouldn't be able to see any page in the site at all (you stated you used Disallow: /. If the robots however do not respect your robots.txt file, then they would be able to see the content, as the redirection is made server side.

My code was checked and seems OK so maybe the problem lies in the htaccess file whose content on my online server is: SetEnv PHP_VER 5_4 Options -Indexes ErrorDocument 404 /index.php RewriteEngine

  • got the same problem with only [L] flag. This occured when changing hosting so i guess this is, somehow, config related.
  • Here's a good link about [P] flag :)…
  • This seems like a replacement to apache's existing 404 handling. More to the point, this doesn't seem to address the question.
  • The [R=301] will break POST requests (form data lost), but leaving it out will not affect the address bar. For this reason, you would want to avoid doing this kind of rewrite if (ever) POSTing to index.
  • Yep. One could always add a RewriteCond %{REQUEST_METHOD} !POST before the rewrite, but is hesitate to think why any form would still have index.php as an action ...