如何使用.htaccess创建用户友好的URL?

Here is the html form with select tag with option value :

<select class="form-control" id="basic" name="location" required>
<?php
$get_location = mysqli_query($conn, "SELECT * FROM product_sub_area");
if(mysqli_num_rows($get_location) == 0 ) {
    $choose = 'No City found';
} else {
    $choose = 'Choose City';
}
?>
<option value=""><?php echo $choose; ?></option>
<?php                                         
while($get_location_result = mysqli_fetch_array($get_location) ) {
    $location_id = (int) $get_location_result['psub_area_id'];
    $location_name = htmlspecialchars($get_location_result['psub_name']);
    echo "<option value='$location_name'>$location_name</option>";
}
?>                    
</select>

After submit this form, page url is showing like this :

http://localhost/freelancer/sitename/location?location=California

I want the url should look like this for every same type of url request. It could be multiple query string :

http://localhost/freelancer/sitename/location/California

I am using following .httaccess rules :

ErrorDocument 404 /not-found.php
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php [NC,L]
RewriteRule ^([^/\.]+)/([^/\.]+)$ location.php?location=$1 [NC,L]  

Try this in sitename folder, what i observe from your requirement you are removing php extension and rewriting request to location parameter.

ErrorDocument 404 not-found.php
RewriteEngine On        

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^location/([\w-]+)$ location.php?location=$1 [QSA,NC,L]

RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php [NC,L]

In this case you have to use a JavaScript to trigger on the submit, which then alters the URL submitted to include just the state name. You can either use jQuery for this, or standard JS. The two solutions are pretty similar, so you can rework the jQuery to vanilla pretty easily.

Reason why you have to use JS is because this all happens before you're sending the request to the server, and it is this very request that you want to change.

PS: Remember to add fallbacks for non-JS enabled browsers (yes, they do exist) and web-crawlers.