php – Ajax returns error after modifying htaccess


I modified the .htaccess with a rule for the url to be passed as a GET parameter and I handle everything in index.php :

Options +FollowSymLinks

RewriteEngine On

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

RewriteRule ^(.*)$ index.php?params=$1 [QSA]

After this change, the ajax (post) below returns as an error and does not complete my request:

            type : 'post',
            url : "",
                nomepagina: $('#nome-pagina').val(),
                idcategoria: $('#id-categoria').val(),
                idpaginacurtir: $('#id-pagina-curtir').val(),
                youtube: getYoutubeId($('#youtube').val()) 
            dataType : "json",
            beforeSend : function()
            success : function(data)
                if (data.cod == 1)

I'm not able to solve this problem, I believe the URL is being rewritten with the .htaccess rule and the POST is not recognized in the criar-pagina-ajax.php .


Yes, the problem in this case is the URL. See how the solution is to change your URL:



So when you split your URL that you are getting by the variable $_GET['params'] in index.php will see that the request is to create the page, and you can call the function that is written in the criar-pagina-ajax.php script criar-pagina-ajax.php

A basic example in index.php :

$requisicao = explode("/", $_GET['params']);
$parametro = $requisicao[count($requisicao) - 1]; // $parametro = "criar-pagina"
if ($parametro == "criar-pagina") {
    // Faça alguma coisa
Scroll to Top