0

i want to send id and post caption through my page to the post page. When i try to GET id only, it works but when i try to get caption it does not work. can someone please help? It's been many days but cannnot get rid of this error. Thank you

.htaccess-rule

RewriteRule ^post/([0-9]+)/([0-9a-zA-Z]+)$ post.php?id=$1&cap=$2 [QSA,L]

Sending it from list page

$cp = preg_replace('/[^A-Za-z0-9\-]+/', '-', $row['caption']);
$cpnew = str_replace(" ", "-", $cp);
<?php echo "<a href='post/$id/$cpnew'>"; ?>

Getting on post page

$cap ="". preg_replace('^[\x{0590}-\x{05fe} ]+', '', $_GET['cap']);
$capnew = str_replace("-", " ", $cap);
M. Eriksson
  • 13,450
  • 4
  • 29
  • 40
  • 2
    No `-` in your rewrite rule? If your caption contains `-` it won't be caught by your rule – brombeer Jan 07 '23 at 12:16
  • 1
    A better way would be to add a "slug" column to your database table. Then when you store the caption, you store the slug as well (result of your `preg_replace()`). Then you only need to use and match it "as is" instead of repeatedly using `preg_replace()`. I also don't get the point of using _both_ the id and caption in the URL for identification. Why not just one or the other? – M. Eriksson Jan 07 '23 at 12:18
  • the issue was no - in rewrite rule. Thank you it worked. – Muhammad Sadiq Feb 12 '23 at 13:34

0 Answers0