Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

134
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda