Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

133
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!