So I've used mod_rewrite to rewrite my get query urls from /news?news_id=6 to /news/6. But now I'd like to be able to also do the same for when somebody submits a form using a get method. Right now when you submit a form it still directs you to /news/news_id=6 instead of /news/6, how would I be able to clean the get query url? I'm pretty sure this can't be done using mod_rewrite (please correct me if you can do so), so I imagine you'd need to use either Javascript or PHP. I've been trying to do this with PHP and so far I've done as follows:
if (!empty($_GET['news_id'])) {
$redirecturl = "/news/" . $_GET['news_id'];
$redirecturl = str_replace(" ", "-", $redirecturl);
header('Location: ' . $redirecturl, true, 303);
die();
}
However this results in an error on the browser which says "localhost redirected you too many times." How would I go about achieving this task with PHP?
Thank you.