使用.htaccess重写post.php?post_id = 20到/ post / this-is-the-title /

I am new to .htacces and for ages I have been trying to get my domain from:

www.domain.com/post.php?post_id=20

to something such as this:

www.domain.com/post/this-is-the-title/

As I said I am new to .htaccess but anything would help please! NOTE: I would be getting the titles of my blog posts from an SQL database somehow

If the page titles are database-driven (or otherwise dynamic), I don't see how you could get away with .htaccess rewrites. It would make more sense to use routing in your PHP script.

I have written about an extremely simple routing method here. It's for people only getting into the subject, but you should be able to build a database-driven router based on that.

Essentially, route all your traffic through index.php and there, get the request URI and decide what resources to load.

[EDIT]

Let me elaborate a bit, using the info from my blog post.

Assuming you have your site set up and running, first direct the traffic to index.php. You do that in .htaccess and it can be done like this:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]

Then, in index.php (or in a script that's called from index.php), you can get the request URI:

$uri = $_SERVER["REQUEST_URI"];

OK, so far so good. Now let's assume your database holds page content along with the page aliases. The uri will most probably be the page alias, so all you need to do is something like this:

$pdo = new PDO(/* your db connection params */);
$page = $pdo
    ->query("SELECT * FROM pages WHERE alias = :alias",
    array("alias" => $uri)
    )
    ->fetch();

At this point you should have the page content corresponding to the title (or alias) in the URI string. All you need to do now is display it any way you want:

echo $page["content"];

You can't. You have to put the title on the query string. An .htaccess cannot safely get anything from the database. Since you are going to rewrite the url, why not simply write the post title in the URI?

You can't do this with an .htaccess cause you need to get "the titles of your blog posts from an SQL database somehow", do a redirect with PHP. :)