HTACCESS gets GET, but prevents receiving POST

Asked

Viewed 39 times

0

I am using the following command in HTACCESS to use Friendly URL:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-z0-9-]+)/?$ index.php?id_cotacao=$1 [NC,L]

It is working, the parameter is being received by the URL as follows site.com/proposta/310, in case the 310 is the registration ID in the bank.

However, I have a form that has its action in this same file. The form passes the values via POST, but the file does not identify the method.

The intention is that this file can receive the form via POST and also the parameter via GET in a "friendly way".

  • Hello Rendesson, welcome. Try adding in your question more information like folder structure, where your file is. htaccess the index.php file, the POST request error, etc. The more information you provide, the easier it will be for someone to help you.

1 answer

1

Your rule apparently is built wrong.

RewriteRule ^([a-z0-9-]+)/?$ index.php?id_cotacao=$1 [NC,L]

You are saying that any url that starts with characters that can contain azinho and Zezinho, numbers between zero and nine and dash character, one or more characters will be rewritten if there are no directories on the server with that name. In reality your url starts with the word "PROPOSED" and the argument passed is an integer.

the correct would be :

Use this way if the quotation id uses letters, numbers and dash:

RewriteRule ^proposta/([a-z0-9-]+)/?$ index.php?id_cotacao=$1 [NC,L]

Or so, if you only have numbers as mentioned in the question.

RewriteRule ^proposta/([0-9]+)/?$ index.php?id_cotacao=$1 [NC,L]

I believe that should be the problem, correct and test your GET and POST and always use the tester as in the image below:

inserir a descrição da imagem aqui inserir a descrição da imagem aqui

Url tester for htacess regex: https://htaccess.madewithlove.be/

Updated Response:

You can block a post request by htacess on this condition

     RewriteCond %{REQUEST_METHOD} POST 

but in the question just put an excerpt that has nothing to do with blocking urls by POST or GET. In this case the lock must be in the configuration files on your apache server or mistakenly edited your HTACCESS. I would need to open your httpd.conf and check, I have no further information to help you.

You can use it on the linux command whereis httpd.conf to locate the path to the installation directory, apache configuration file is there.

Be aware that your rule does not work if there is a file (!-F) or directory (!-d) called proposed created on the server, due to these two configuration lines.

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

These are the guidelines I can give you with what you informed in your question if you can add more information maybe I can go further.

  • It didn’t solve the problem, even GET stopped. "Not Found. The requested URL was not found on this server."

  • I edited my reply by providing new information

Browser other questions tagged

You are not signed in. Login or sign up in order to post.