繁体   English   中英

如何使用mod_rewrite重写url

[英]How to rewrite url using mod_rewrite

我的网址目前看起来像这样:

http://domain.com/news/articles.php?id=22&category=investments&title=securing-your-future-making-the-right-investment

如何使用mod_rewrite使网址看起来像这样:

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

编辑:也需要包含id变量

在您的.htaccess文件中添加以下内容:

^ / news / articles /([[0-9] +)/(。*)$ secure-you-future-make-the-right-investment $ /news/articles.php?id=$1&category=$3s&title=$2 [L]

不了解这3美元,但您列出的网址中似乎没有类别,因此我认为它不是必需的。

这应该使它工作;)

#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

该ID必须存在于URL中,因此它看起来像:

http://domain.com/news/articles/investments/ {ID} _securing-your-future-making-the-right-investment

祝好运。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM