开发者

How to rewrite url using mod_rewrite

开发者 https://www.devze.com 2023-04-06 23:44 出处:网络
My urls currently look like this: http://domain.com/news/articles.php?id=22&category=investments&title=securing-your-future-making-the-right-investment

My urls currently look like this:

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

How can I use mod_rewrite to make the url look more like this:

http://domain.com/news/articles/investments/securing-your开发者_运维知识库-future-making-the-right-investment

EDIT: need to include the id variable too


#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

the ID must exist in the URL so the it looks like:

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

Good luck.


Add something like this to your .htaccess file:

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

Don't know about the $3, but category doesn't seem to be present in the url you listed so I guess it isnt needed.

This should make it work ;)

0

精彩评论

暂无评论...
验证码 换一张
取 消