TL;DR
turn search.php?key=value => value.php
I have a simple project:
|-project
|-----.htaccess
|-----index.php
|-----jquery.min.js
|-----search.php
All I'm trying to learn is how to turn query params into page.php, e.g.:
?search=test
becomestest.php
I found this SO post: htaccess rewrite for query string
Which suggests 3 methods of doing it, I've tried all yet my search.php doesn't work.
Here is my index.php
<html>
<body>
<form method="post">
<input type="text" name="search" placeholder="search something" />
</form>
<button type="button" id="my-btn">Submit</button>
<script src="jquery.min.js"></script>
<script>
jQuery(document).ready(function($)
{
$('#my-btn').click(function()
{
let val = $('input[type="text"]').val();
$('form').attr('action', 'search.php?term='+ val);
$('form').submit()
})
})
</script>
</body>
</html>
which goes to search.php
<?php
$search = $_GET['search'];
echo '<pre>';
echo 'Search Term: <strong>'. $search .'</strong>';
echo '</pre>';
echo '<hr />';
and my .htaccess file looks like this:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /search.php?term=$1 [L]
But this (or the other methods) didn't work. My url still is search.php?term=test
- how do I go about achieving my goal?