Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

135
Visualizações
Rewrite Delete Href link

I have been struggling with this rewrite rule for a few days, I have searched on here and tried many different rewrite rules I not sure what I am missing.

this is my PHP request to the database.

<?php
if (isset($_GET['delete'])){

    $ServerID = $_GET['delete'] ;

    $db = dbconnect();
    $stmt = $db->prepare("DELETE FROM servers WHERE ID = $ServerID");
    $stmt->execute();
    $stmt->close();

   }
?>

My HTML link that deletes the record for me

 <a href="servers.php?delete='.$ServerID.'">Delete</a>

and when you hover the above link it shows as follows

http://example.com/servers.php?delete=12

in my .htaccess I used the script to remove the .php at the end and used the following rewrite rule

RewriteRule ^servers/delete/(\d+)$ servers.php?delete=$1 [NC,L]

an then changed my HTML link to the following

<a href="servers/delete/'.$ServerID.'">Delete</a>

now when i hover the link i can see it rewrites the string to this

http://example.com/servers/delete/12

but when I click it it does not delete the record, it pulls up a URL like a page when all it should do is delete the record

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

According to your comment to the question you learned from the http server's error log file that the actual issue is a rewriting loop you created by your rewriting rule.

The actual rule you implemented is perfectly fine. But you need to take care that it is only applied of the request does not already point to the rewrite target:

RewriteEngine on
RewriteCond %{REQUEST_URI} ! /servers\.php$
RewriteRule ^servers/delete/(\d+)$ servers.php?delete=$1 [NC,L]

A much easier approach however would be to use the END flag instead of the older L flag in the rule itself:

RewriteEngine on
RewriteRule ^servers/delete/(\d+)$ servers.php?delete=$1 [NC,END]

See the documentation of the rewriting module to understand the difference: https://httpd.apache.org/docs/current/mod/mod_rewrite.html

And a general remark: you should always prefer to place such rules in the http servers host configuration instead of using distributed configuration files (".htaccess"). Those distributed configuration files add complexity, are often a cause of unexpected behavior, hard to debug and they really slow down the http server. They are only provided as a last option for situations where you do not have access to the real http servers host configuration (read: really cheap service providers) or for applications insisting on writing their own rules (which is an obvious security nightmare).

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda