'Changing URL using htaccess for seo

I am trying to make SEO friendly, my URL is https://example.com/blog/single.php?blog=BLOG_TITLE&id=27, I want to make it https://example.com/blog/single.php/BLOG_TITLE.

From id in URL, I am fetching blog details using ajax from the database.

code I wrote to redirect page

function blogSingle(heading, id ){
            if(id){
                location.href = "https://example.com/blog/single.php? 
                 blog="+heading.trim().replace(/\s+/g, '-')+"&id="+id+""
            }
        }

Please help me to fix this.



Solution 1:[1]

If you have a .htaccess file, I assume you are using Apache.

You may want to use the mod_rewrite module to realise URL rewriting.

Here is an example how to do that: https://www.digitalocean.com/community/tutorials/how-to-rewrite-urls-with-mod_rewrite-for-apache-on-ubuntu-16-04

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Almaju