Php 如何使用mod_rewrite重写url

Php 如何使用mod_rewrite重写url,php,apache,url,mod-rewrite,seo,Php,Apache,Url,Mod Rewrite,Seo,我的URL当前如下所示: http://domain.com/news/articles.php?id=22&category=investments&title=securing-your-future-making-the-right-investment 如何使用mod_rewrite使url看起来更像这样: http://domain.com/news/articles/investments/securing-your-future-making-the-right-

我的URL当前如下所示:

http://domain.com/news/articles.php?id=22&category=investments&title=securing-your-future-making-the-right-investment
如何使用mod_rewrite使url看起来更像这样:

http://domain.com/news/articles/investments/securing-your-future-making-the-right-investment

编辑:也需要包含id变量

将类似的内容添加到.htaccess文件中:

^/新闻/文章/([0-9]+)/(.*)$确保您的未来做出正确的投资$ /news/articles.php?id=$1和category=$3s和title=$2[L]

我不知道3美元,但你列出的url中似乎没有类别,所以我猜不需要

这应该会让它起作用;)

该ID必须存在于URL中,以使其看起来像:

{ID}{u确保你未来的正确投资


祝你好运。

你的脚本不需要id变量吗?哦,是的,id变量很重要。堆栈溢出问题至少有5000个问题,可能更多,或多或少都是这个问题的变体,只是变量名不同而已。此外,谷歌搜索“重写URL mod_rewrite”将提供数十个有用的教程和分步指南。为什么不先自己做些调查呢?这并不是很难,即使你对mod_重写一无所知。如果你在这个过程中遇到困难,你仍然可以在这里问。
#enable mod rewrite
RewriteEngine On
RewriteRule ^/news/articles.php?id=([0-9]+)&category=([a-zA-Z]+)&title=([a-zA-Z]+)$ /news/articles/$2/$1_$3